heyquilt 0.3.165 → 0.3.168
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 +15 -0
- package/package.json +1 -1
- package/src/account.js +10 -0
- package/src/api/audit.js +0 -1
- package/src/api/composio.js +1 -64
- package/src/api/memory-store.js +17 -8
- package/src/api/routes/connections.js +1 -78
- package/src/api/routes/workspaces.js +3 -43
- package/src/api/server.js +66 -6
- package/src/api/supabase-store.js +24 -12
- package/src/control.js +0 -21
- package/src/presence.js +1 -2
- package/src/server.js +1 -15
- package/src/ui/app.css +8 -744
- package/src/ui/app.js +24 -38
- package/src/ui/board.js +7 -17
- package/src/ui/connections.js +41 -235
- package/src/ui/feed.js +8 -23
- package/src/ui/files.js +22 -67
- package/src/ui/home.js +6 -95
- package/src/ui/loom-model.js +8 -11
- package/src/ui/loom.css +2 -183
- package/src/ui/loom.js +55 -132
- package/src/ui/secrets.js +3 -1
- package/src/ui/session.js +75 -1065
- package/src/ui/signin.js +80 -5
- package/src/ui/workspaces.js +1 -2
- package/src/ui-server.js +37 -53
- package/src/dev-servers.js +0 -65
- package/src/ui/home-view.js +0 -170
- package/src/ui/palette.js +0 -75
- package/src/ui/people-view.js +0 -116
package/src/ui/signin.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// The sign-in screen. Until this computer is linked to a heyquilt.com account the
|
|
2
|
-
// app shows only this. Signing in opens the website, where you approve this computer
|
|
2
|
+
// app shows only this. Signing in opens the website, where you approve this computer;
|
|
3
|
+
// signing up happens right here, confirmed by a code emailed to you, and links this computer.
|
|
3
4
|
import { $, esc, api, loadingNote } from './common.js'
|
|
4
5
|
import { quiltMark } from './mark.js'
|
|
5
6
|
|
|
@@ -18,22 +19,96 @@ function screen (inner) {
|
|
|
18
19
|
export function renderSignIn (message = '', onSignedIn = () => window.location.reload()) {
|
|
19
20
|
screen(`
|
|
20
21
|
<h1>Sign in to Quilt</h1>
|
|
21
|
-
<p class="signin-lead">Your sessions, files and agents, in one place. Signing in opens heyquilt.com in your browser, where you approve this computer.</p>
|
|
22
22
|
${message ? `<p class="signin-note">${esc(message)}</p>` : ''}
|
|
23
23
|
<button class="btn primary signin-btn" id="signin-go">Sign in</button>
|
|
24
|
-
<p class="hint">New to Quilt? <a href="${SIGNUP}" target="_blank" rel="noopener">Create an account</a></p>
|
|
24
|
+
<p class="hint">New to Quilt? <a href="${SIGNUP}" id="signin-new" target="_blank" rel="noopener">Create an account</a></p>
|
|
25
25
|
<p class="error" id="signin-error"></p>`)
|
|
26
26
|
$('#signin-go').onclick = () => begin(onSignedIn)
|
|
27
|
+
$('#signin-new').onclick = (e) => { e.preventDefault(); renderSignUp(onSignedIn) }
|
|
27
28
|
}
|
|
28
29
|
|
|
29
|
-
|
|
30
|
+
/** Signing up in the app: name, email and password, then the code Quilt emails. This computer is signed in to the new account. */
|
|
31
|
+
function renderSignUp (onSignedIn, values = {}) {
|
|
32
|
+
screen(`
|
|
33
|
+
<h1>Create your Quilt account</h1>
|
|
34
|
+
<form class="signup-form" id="signup-form" novalidate>
|
|
35
|
+
<div class="field"><label for="su-name">Your name</label><input class="input" id="su-name" autocomplete="name" maxlength="60" value="${esc(values.name || '')}" required></div>
|
|
36
|
+
<div class="field"><label for="su-email">Email</label><input class="input" id="su-email" type="email" autocomplete="email" value="${esc(values.email || '')}" required></div>
|
|
37
|
+
<div class="field"><label for="su-password">Password <span class="hint">at least 8 characters</span></label><input class="input" id="su-password" type="password" autocomplete="new-password" minlength="8" required></div>
|
|
38
|
+
<button class="btn primary signin-btn" id="su-go" type="submit">Create account</button>
|
|
39
|
+
</form>
|
|
40
|
+
<p class="error" id="signin-error"></p>
|
|
41
|
+
<p class="hint">Already have an account? <a href="#" id="su-signin">Sign in</a></p>
|
|
42
|
+
<p class="hint">Or <a href="${SIGNUP}" id="su-web" target="_blank" rel="noopener">sign up in your browser</a></p>`)
|
|
43
|
+
$('#su-name').focus()
|
|
44
|
+
$('#su-signin').onclick = (e) => { e.preventDefault(); renderSignIn('', onSignedIn) }
|
|
45
|
+
// On the website, sign-up comes back to approving this computer.
|
|
46
|
+
$('#su-web').onclick = (e) => { e.preventDefault(); begin(onSignedIn, true) }
|
|
47
|
+
$('#signup-form').onsubmit = async (e) => {
|
|
48
|
+
e.preventDefault()
|
|
49
|
+
const details = { name: $('#su-name').value.trim(), email: $('#su-email').value.trim(), password: $('#su-password').value }
|
|
50
|
+
if (!details.name || !details.email || !details.password) return fail('Fill in your name, email and a password.')
|
|
51
|
+
if (details.password.length < 8) return fail('Use a password of at least 8 characters.')
|
|
52
|
+
$('#su-go').disabled = true
|
|
53
|
+
try {
|
|
54
|
+
const acc = await api('POST', '/api/account/signup', details)
|
|
55
|
+
if (acc.signedIn) return onSignedIn()
|
|
56
|
+
renderCode(onSignedIn, details)
|
|
57
|
+
} catch (err) {
|
|
58
|
+
$('#su-go').disabled = false
|
|
59
|
+
fail(err.message)
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function renderCode (onSignedIn, details) {
|
|
65
|
+
screen(`
|
|
66
|
+
<h1>Check your email</h1>
|
|
67
|
+
<p>We sent a 6-digit code to <b>${esc(details.email)}</b>.</p>
|
|
68
|
+
<form class="signup-form" id="code-form" novalidate>
|
|
69
|
+
<div class="field"><label for="su-code">Code</label><input class="input signup-code" id="su-code" inputmode="numeric" autocomplete="one-time-code" maxlength="7" required></div>
|
|
70
|
+
<button class="btn primary signin-btn" id="code-go" type="submit">Continue</button>
|
|
71
|
+
</form>
|
|
72
|
+
<p class="error" id="signin-error"></p>
|
|
73
|
+
<p class="hint">No email? Check spam, or <a href="#" id="code-again">send a new code</a>. <a href="#" id="code-back">Use a different email</a></p>`)
|
|
74
|
+
$('#su-code').focus()
|
|
75
|
+
$('#code-back').onclick = (e) => { e.preventDefault(); renderSignUp(onSignedIn, details) }
|
|
76
|
+
$('#code-again').onclick = async (e) => {
|
|
77
|
+
e.preventDefault()
|
|
78
|
+
try { await api('POST', '/api/account/signup', details); fail('A new code is on its way.') } catch (err) { fail(err.message) }
|
|
79
|
+
}
|
|
80
|
+
$('#code-form').onsubmit = async (e) => {
|
|
81
|
+
e.preventDefault()
|
|
82
|
+
const code = $('#su-code').value.replace(/\s+/g, '')
|
|
83
|
+
if (!/^\d{6}$/.test(code)) return fail('Enter the 6-digit code from the email.')
|
|
84
|
+
$('#code-go').disabled = true
|
|
85
|
+
try {
|
|
86
|
+
const acc = await api('POST', '/api/account/signup/confirm', { code })
|
|
87
|
+
if (acc.signedIn) return onSignedIn()
|
|
88
|
+
$('#code-go').textContent = 'Signing in…'
|
|
89
|
+
// Confirmed: the app collects this computer's sign-in within a few seconds.
|
|
90
|
+
poller = setInterval(async () => {
|
|
91
|
+
const now = await api('GET', '/api/account').catch(() => null)
|
|
92
|
+
if (now?.signedIn) { clearInterval(poller); onSignedIn() }
|
|
93
|
+
}, 1000)
|
|
94
|
+
} catch (err) {
|
|
95
|
+
$('#code-go').disabled = false
|
|
96
|
+
fail(err.message)
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const fail = (message) => { $('#signin-error').textContent = message }
|
|
102
|
+
|
|
103
|
+
async function begin (onSignedIn, signup = false) {
|
|
30
104
|
const btn = $('#signin-go')
|
|
31
105
|
btn.disabled = true
|
|
32
106
|
try {
|
|
33
107
|
const acc = await api('POST', '/api/account/start')
|
|
34
108
|
// A computer linked before is signed straight back in: nothing to approve.
|
|
35
109
|
if (acc.signedIn) return onSignedIn()
|
|
36
|
-
|
|
110
|
+
const verify = new URL(acc.link.verificationUrl)
|
|
111
|
+
window.open(signup ? `${SIGNUP}?next=${encodeURIComponent(verify.pathname + verify.search)}` : verify.href, '_blank', 'noopener')
|
|
37
112
|
waiting(acc.link, onSignedIn)
|
|
38
113
|
} catch (err) {
|
|
39
114
|
btn.disabled = false
|
package/src/ui/workspaces.js
CHANGED
|
@@ -369,8 +369,7 @@ export function bindWorkspacePage (root, { go, rerender, newSessionDialog, invit
|
|
|
369
369
|
if (!d || d.workspace.id !== String(state.view).slice(3)) return
|
|
370
370
|
const id = d.workspace.id
|
|
371
371
|
const reload = async () => { await openWorkspace(id); await loadWorkspaces(); rerender() }
|
|
372
|
-
|
|
373
|
-
if (back) back.onclick = (e) => { e.preventDefault(); go('home') }
|
|
372
|
+
root.querySelector('[data-ws-back]').onclick = (e) => { e.preventDefault(); go('home') }
|
|
374
373
|
root.querySelectorAll('[data-go]').forEach((b) => { b.onclick = () => go(b.dataset.go) })
|
|
375
374
|
root.querySelector('[data-new-session-in]')?.addEventListener('click', () => newSessionDialog(id))
|
|
376
375
|
root.querySelector('[data-invite-ws]')?.addEventListener('click', () => inviteDialog(id))
|
package/src/ui-server.js
CHANGED
|
@@ -18,10 +18,9 @@ import { execFile } from 'node:child_process'
|
|
|
18
18
|
import { installedEditors, openIn, copyToClipboard } from './editors.js'
|
|
19
19
|
import { autowork, autoConfig, publicConfig, AUTO_MODES } from './autowork.js'
|
|
20
20
|
import { migrateDir } from './legacy.js'
|
|
21
|
-
import { devServers } from './dev-servers.js'
|
|
22
21
|
import { writePrivateJson } from './private-file.js'
|
|
23
22
|
import { autoToolFor } from './autowork-tools.js'
|
|
24
|
-
import { readAccount, saveAccount, clearAccount, clearAccountIf, resumeAccount, startLink, waitForLink, 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, apiUrl } from './account.js'
|
|
23
|
+
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, apiUrl } from './account.js'
|
|
25
24
|
import { aiName } from './persona.js'
|
|
26
25
|
import { effectiveAccess, builtinType } from './session-access.js'
|
|
27
26
|
import { cleanSessionName, BAD_SESSION_NAME, SESSION_NAME_MAX } from './session-name.js'
|
|
@@ -52,7 +51,7 @@ const LOCAL_RELAY_GONE = "This session ran on your computer's own relay, which Q
|
|
|
52
51
|
export const GITHUB_GONE = 'Starting a session from GitHub is gone: start one from a folder (a new session\'s code is committed in Seam from the start), and bring a repository\'s history into Seam with seam github import.'
|
|
53
52
|
const STATUS_PUSH_MS = 500 // a session's status goes to the window at most this often when the session changes it
|
|
54
53
|
// Until this computer is signed in, only these answer.
|
|
55
|
-
const OPEN_ROUTES = new Set(['GET /api/account', 'POST /api/account/start', 'POST /api/account/cancel', 'POST /api/account/signout', 'GET /api/events', 'POST /api/shutdown', 'POST /api/report'])
|
|
54
|
+
const OPEN_ROUTES = new Set(['GET /api/account', 'POST /api/account/start', 'POST /api/account/signup', 'POST /api/account/signup/confirm', 'POST /api/account/cancel', 'POST /api/account/signout', 'GET /api/events', 'POST /api/shutdown', 'POST /api/report'])
|
|
56
55
|
|
|
57
56
|
// The sound switches in Settings, one per event (SOUND_EVENTS in src/ui/sounds.js).
|
|
58
57
|
const SOUND_SETTINGS = ['soundMentions', 'soundLetIn', 'soundTasks']
|
|
@@ -217,9 +216,6 @@ export const STATIC = {
|
|
|
217
216
|
'/secrets.js': ['secrets.js', 'text/javascript; charset=utf-8'],
|
|
218
217
|
'/secrets-view.js': ['secrets-view.js', 'text/javascript; charset=utf-8'],
|
|
219
218
|
'/connections.js': ['connections.js', 'text/javascript; charset=utf-8'],
|
|
220
|
-
'/home-view.js': ['home-view.js', 'text/javascript; charset=utf-8'],
|
|
221
|
-
'/people-view.js': ['people-view.js', 'text/javascript; charset=utf-8'],
|
|
222
|
-
'/palette.js': ['palette.js', 'text/javascript; charset=utf-8'],
|
|
223
219
|
'/secret-rules.js': ['secret-rules.js', 'text/javascript; charset=utf-8'],
|
|
224
220
|
'/voice.js': ['voice.js', 'text/javascript; charset=utf-8'],
|
|
225
221
|
'/voice-model.js': ['voice-model.js', 'text/javascript; charset=utf-8'],
|
|
@@ -238,8 +234,6 @@ const CSP = [
|
|
|
238
234
|
"style-src 'self' 'unsafe-inline'",
|
|
239
235
|
"img-src 'self' data: https: https://www.google.com https://*.gstatic.com",
|
|
240
236
|
"font-src 'self'",
|
|
241
|
-
// The Preview tab shows the session's links (a dev server, staging, production) in a sandboxed frame.
|
|
242
|
-
"frame-src http: https:",
|
|
243
237
|
"connect-src 'self'",
|
|
244
238
|
"object-src 'none'",
|
|
245
239
|
"base-uri 'none'",
|
|
@@ -352,7 +346,8 @@ export async function startUi ({ port = 7420, onShutdown, preview = false, repor
|
|
|
352
346
|
|
|
353
347
|
/** Starts linking this computer; the website approves it, and we collect the token in the background. */
|
|
354
348
|
async function beginLink () {
|
|
355
|
-
|
|
349
|
+
// Already signed in (approved while the window lost track of it): say so, and the app goes on in.
|
|
350
|
+
if (readAccount()) return accountState()
|
|
356
351
|
// A computer linked before signs straight back in: no browser, no approving it again.
|
|
357
352
|
try {
|
|
358
353
|
if (await resumeAccount({ asked: true })) {
|
|
@@ -364,6 +359,12 @@ export async function startUi ({ port = 7420, onShutdown, preview = false, repor
|
|
|
364
359
|
return accountState()
|
|
365
360
|
}
|
|
366
361
|
} catch {}
|
|
362
|
+
await newLink()
|
|
363
|
+
return accountState()
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/** A fresh link for this computer, collected in the background once it's approved (on the website, or by a sign-up code). */
|
|
367
|
+
async function newLink () {
|
|
367
368
|
const identity = loadIdentity()
|
|
368
369
|
const mine = { ...await startLink({ identity }), state: 'waiting', error: null }
|
|
369
370
|
link = mine
|
|
@@ -393,6 +394,27 @@ export async function startUi ({ port = 7420, onShutdown, preview = false, repor
|
|
|
393
394
|
mine.state = err.expired ? 'expired' : err.denied ? 'denied' : 'failed'
|
|
394
395
|
mine.error = err.message
|
|
395
396
|
})
|
|
397
|
+
return mine
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* Signing up in the app: the account is made on Quilt's API for a link this computer starts
|
|
402
|
+
* (or the one it's waiting on), and the emailed code approves that link for it. No browser.
|
|
403
|
+
*/
|
|
404
|
+
async function signUp ({ name, email, password }) {
|
|
405
|
+
if (readAccount()) return accountState()
|
|
406
|
+
const mine = link && link.state === 'waiting' ? link : await newLink()
|
|
407
|
+
const r = await signUpForLink({ deviceCode: mine.deviceCode, name, email, password }).catch((err) => { throw httpError(err.status && err.status < 500 ? 400 : 502, err.message) })
|
|
408
|
+
mine.signUpEmail = r.email
|
|
409
|
+
return { ...await accountState(), signUp: { email: r.email } }
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
async function confirmSignUp ({ code }) {
|
|
413
|
+
if (readAccount()) return accountState()
|
|
414
|
+
const mine = link
|
|
415
|
+
if (!mine || mine.state !== 'waiting' || !mine.signUpEmail) throw httpError(409, 'That sign-up timed out. Start again.')
|
|
416
|
+
await confirmSignUpForLink({ deviceCode: mine.deviceCode, email: mine.signUpEmail, code }).catch((err) => { throw httpError(err.status && err.status < 500 ? 400 : 502, err.message) })
|
|
417
|
+
// Approved: the link's own poll collects the sign-in within a few seconds.
|
|
396
418
|
return accountState()
|
|
397
419
|
}
|
|
398
420
|
|
|
@@ -962,9 +984,7 @@ export async function startUi ({ port = 7420, onShutdown, preview = false, repor
|
|
|
962
984
|
const enc = (v) => encodeURIComponent(String(v))
|
|
963
985
|
return asAccount(async (token) => {
|
|
964
986
|
const c = secretsApi(token)
|
|
965
|
-
|
|
966
|
-
if (method === 'GET' && oneApp) return apiCall(c, 'GET', `/v1/connections/apps/${oneApp[1]}`)
|
|
967
|
-
if (method === 'GET' && p === '/api/connections/apps') return apiCall(c, 'GET', `/v1/connections/apps?search=${enc(url.searchParams.get('search') || '')}&group=${enc(url.searchParams.get('group') || '')}&offset=${enc(url.searchParams.get('offset') || '0')}&limit=${enc(url.searchParams.get('limit') || '48')}`)
|
|
987
|
+
if (method === 'GET' && p === '/api/connections/apps') return apiCall(c, 'GET', `/v1/connections/apps?search=${enc(url.searchParams.get('search') || '')}&limit=${enc(url.searchParams.get('limit') || '60')}`)
|
|
968
988
|
const sc = p.match(/^\/api\/connections\/(org|workspace|session)\/([^/]+)(?:\/([0-9a-f-]{36}))?$/i)
|
|
969
989
|
if (sc && SECRET_SCOPE_ID[sc[1]].test(decodeURIComponent(sc[2]))) {
|
|
970
990
|
const base = `/v1/connections/${sc[1]}/${enc(decodeURIComponent(sc[2]))}`
|
|
@@ -1033,22 +1053,6 @@ export async function startUi ({ port = 7420, onShutdown, preview = false, repor
|
|
|
1033
1053
|
'GET /api/orgs': () => asAccount(async (token) => ({ orgs: await listOrgs({ token }) })),
|
|
1034
1054
|
'POST /api/workspaces': (b) => asAccount(async (token) => ({ workspace: await createWorkspace({ token, name: String(b.name || ''), description: String(b.description || ''), color: String(b.color || ''), org: b.org ? String(b.org) : undefined }) })),
|
|
1035
1055
|
'GET /api/workspaces/:id': (b, id) => asAccount(async (token) => ({ ...(await getWorkspace({ token, id: needWorkspaceId(id) })), ...ofWorkspace(id) })),
|
|
1036
|
-
// The workspace's home (plans/app-redesign.md): AI time from the accounts API, merges onto main from Seam for
|
|
1037
|
-
// the workspace's sessions open on this computer, and its links (previews).
|
|
1038
|
-
'GET /api/workspaces/:id/insights': (b, id) => asAccount(async (token) => {
|
|
1039
|
-
const wid = needWorkspaceId(id)
|
|
1040
|
-
const ai = await apiCall({ api: apiUrl(), token }, 'GET', `/v1/workspaces/${encodeURIComponent(wid)}/insights?days=14`)
|
|
1041
|
-
const since = Date.now() - 14 * 24 * 60 * 60 * 1000
|
|
1042
|
-
const merges = []
|
|
1043
|
-
for (const [key, r] of runs) {
|
|
1044
|
-
const sm = summary(key)
|
|
1045
|
-
if (!sm || sm.workspace !== wid || !r.run.session.seamMerges) continue
|
|
1046
|
-
try { for (const at of await r.run.session.seamMerges({ since })) merges.push({ room: r.run.session.room, at }) } catch {} // one session's Seam not answering leaves its merges out
|
|
1047
|
-
}
|
|
1048
|
-
return { ...ai, merges }
|
|
1049
|
-
}),
|
|
1050
|
-
'POST /api/workspaces/:id/links': (b, id) => asAccount((token) => apiCall({ api: apiUrl(), token }, 'POST', `/v1/workspaces/${encodeURIComponent(needWorkspaceId(id))}/links`, { name: String(b.name || ''), url: String(b.url || ''), room: b.room ? String(b.room) : null, note: String(b.note || '') })),
|
|
1051
|
-
'POST /api/workspaces/:id/links/:lid/remove': (b, id, url, lid) => asAccount(async (token) => { await apiCall({ api: apiUrl(), token }, 'DELETE', `/v1/workspaces/${encodeURIComponent(needWorkspaceId(id))}/links/${encodeURIComponent(String(lid))}`); return { ok: true } }),
|
|
1052
1056
|
'POST /api/workspaces/:id/update': (b, id) => asAccount(async (token) => ({ workspace: await updateWorkspace({ token, id: needWorkspaceId(id), patch: { name: b.name, description: b.description, color: b.color, archived: b.archived } }) })),
|
|
1053
1057
|
'POST /api/workspaces/:id/delete': (b, id) => asAccount(async (token) => { await deleteWorkspace({ token, id: needWorkspaceId(id) }); return { ok: true } }),
|
|
1054
1058
|
'POST /api/workspaces/:id/members': (b, id) => asAccount(async (token) => ({ member: await putWorkspaceMember({ token, id: needWorkspaceId(id), account: String(b.account || ''), access: String(b.access || ''), sessions: b.sessions === undefined ? undefined : String(b.sessions) }) })),
|
|
@@ -1111,6 +1115,8 @@ export async function startUi ({ port = 7420, onShutdown, preview = false, repor
|
|
|
1111
1115
|
'POST /api/workspaces/:id/files/:fid/delete': (b, id, url, fid) => asAccount(async (token) => { await deleteWorkspaceFile({ token, id: needWorkspaceId(id), fileId: fid }); return { ok: true } }),
|
|
1112
1116
|
'POST /api/workspaces/:id/folders': (b, id) => asAccount(async (token) => ({ file: await createWorkspaceFolder({ token, id: needWorkspaceId(id), path: String(b.path || '') }) })),
|
|
1113
1117
|
'POST /api/account/start': () => beginLink(),
|
|
1118
|
+
'POST /api/account/signup': (b) => signUp(b || {}),
|
|
1119
|
+
'POST /api/account/signup/confirm': (b) => confirmSignUp(b || {}),
|
|
1114
1120
|
'POST /api/account/cancel': () => { link = null; return accountState() },
|
|
1115
1121
|
'POST /api/account/signout': async () => {
|
|
1116
1122
|
const account = readAccount()
|
|
@@ -1141,14 +1147,6 @@ export async function startUi ({ port = 7420, onShutdown, preview = false, repor
|
|
|
1141
1147
|
'POST /api/sessions/:id/focus': (b, id) => { get(id).setFocus(b.text); return { ok: true } },
|
|
1142
1148
|
// Voice (voice.js): the call as this app sees it, and our part in it, from the app window, which does the audio.
|
|
1143
1149
|
'GET /api/sessions/:id/voice': (b, id) => get(id).voice(),
|
|
1144
|
-
// The Calls tab (dm06): the session's calls from their transcripts, newest first, each with its opening lines.
|
|
1145
|
-
'GET /api/sessions/:id/calls': (b, id) => {
|
|
1146
|
-
const { lines, calls } = get(id).voiceTranscript({ limit: 1000 })
|
|
1147
|
-
return { calls: calls.reverse().slice(0, 50).map((c) => ({ ...c, opening: lines.filter((l) => l.call === c.call).slice(0, 3).map((l) => ({ by: l.by, text: l.text })) })) }
|
|
1148
|
-
},
|
|
1149
|
-
// The Preview tab: dev servers running from this session's folder on this computer (dev-servers.js).
|
|
1150
|
-
'GET /api/sessions/:id/dev-servers': async (b, id) => { get(id); return { servers: await devServers(runs.get(id)?.run.dir, { skip: [server.address()?.port].filter(Boolean) }) } },
|
|
1151
|
-
'GET /api/sessions/:id/calls/:call': (b, id, url, call) => ({ lines: get(id).voiceTranscript({ call, limit: 1000 }).lines }),
|
|
1152
1150
|
'POST /api/sessions/:id/voice': (b, id) => get(id).setVoice(b.in === false ? null : { muted: b.muted === true, sig: b.sig, transcribing: b.transcribing === true, sharing: b.sharing === true, agents: b.agents === true }),
|
|
1153
1151
|
'POST /api/sessions/:id/voice/transcribe': (b, id) => get(id).setVoiceTranscribe(b.on === true),
|
|
1154
1152
|
'POST /api/sessions/:id/voice/clip': (b, id) => voiceClip(get(id), b),
|
|
@@ -1220,8 +1218,6 @@ export async function startUi ({ port = 7420, onShutdown, preview = false, repor
|
|
|
1220
1218
|
'GET /api/sessions/:id/search': (b, id, url) => get(id).quiltSearch(String(url.searchParams.get('q') || '')),
|
|
1221
1219
|
// In a session that moved into Seam: the square panel's Commit and Merge onto main, as this member (control.js seamTool).
|
|
1222
1220
|
'POST /api/sessions/:id/seam': (b, id) => squareTool(get(id), b),
|
|
1223
|
-
'GET /api/sessions/:id/github': (b, id) => seamGithub(get(id), {}),
|
|
1224
|
-
'POST /api/sessions/:id/github': (b, id) => seamGithub(get(id), b),
|
|
1225
1221
|
'GET /api/sessions/:id/file': (b, id, url) => {
|
|
1226
1222
|
const f = get(id).readShared(url.searchParams.get('path'))
|
|
1227
1223
|
if (!f) throw httpError(404, 'That file is not in this session.')
|
|
@@ -1266,6 +1262,8 @@ export async function startUi ({ port = 7420, onShutdown, preview = false, repor
|
|
|
1266
1262
|
'GET /api/version': async () => {
|
|
1267
1263
|
const version = currentVersion()
|
|
1268
1264
|
const latest = await latestRelease()
|
|
1265
|
+
// A fresh install has nothing new to tell: its first launch opens on sign-in and Home, not the notes.
|
|
1266
|
+
if (!seenVersion()) markSeen(version)
|
|
1269
1267
|
return {
|
|
1270
1268
|
version,
|
|
1271
1269
|
releases: localReleases(),
|
|
@@ -1407,12 +1405,6 @@ export async function startUi ({ port = 7420, onShutdown, preview = false, repor
|
|
|
1407
1405
|
// A workspace's invite, the same way.
|
|
1408
1406
|
const iid = (url.pathname.match(/^\/api\/workspaces\/[^/]+\/invites\/([^/]+)\//) || [])[1]
|
|
1409
1407
|
if (iid) pathKey = pathKey.replace(/^(\/api\/workspaces\/:id\/invites)\/[^/]+/, '$1/:iid')
|
|
1410
|
-
// A workspace's link (a preview), the same way.
|
|
1411
|
-
const lid = (url.pathname.match(/^\/api\/workspaces\/[^/]+\/links\/([^/]+)\//) || [])[1]
|
|
1412
|
-
if (lid) pathKey = pathKey.replace(/^(\/api\/workspaces\/:id\/links)\/[^/]+/, '$1/:lid')
|
|
1413
|
-
// A call's transcript (the Calls tab), by the call's id.
|
|
1414
|
-
const cid = (url.pathname.match(/^\/api\/sessions\/[a-f0-9]+\/calls\/([^/]+)$/) || [])[1]
|
|
1415
|
-
if (cid) pathKey = pathKey.replace(/^(\/api\/sessions\/:id\/calls)\/[^/]+$/, '$1/:call')
|
|
1416
1408
|
const key = `${req.method} ${pathKey}`
|
|
1417
1409
|
const handler = api[key]
|
|
1418
1410
|
if (!handler) {
|
|
@@ -1424,7 +1416,7 @@ export async function startUi ({ port = 7420, onShutdown, preview = false, repor
|
|
|
1424
1416
|
const body = raw ? JSON.parse(raw) : {}
|
|
1425
1417
|
const startedAt = Date.now()
|
|
1426
1418
|
try {
|
|
1427
|
-
const out = await handler(body, sid, url, fid || aid || iid
|
|
1419
|
+
const out = await handler(body, sid, url, fid || aid || iid)
|
|
1428
1420
|
// A reply that streams (an agent's speech): straight through as it comes.
|
|
1429
1421
|
if (out && out[STREAMED]) {
|
|
1430
1422
|
res.writeHead(200, { 'content-type': out.type, 'cache-control': 'no-store' })
|
|
@@ -1646,14 +1638,6 @@ export function underJoinDir (joinDir, name, message = INVALID_INVITE) {
|
|
|
1646
1638
|
* commits first), as this member through Seam's own tools; or open_square, for a folder whose branch has
|
|
1647
1639
|
* none (Session.openSquareHere). The answer as { text }, a refusal as a 400.
|
|
1648
1640
|
*/
|
|
1649
|
-
/** Session settings' GitHub card: Seam's GitHub (the Seam app's installations, and the quilt's export to a repository). */
|
|
1650
|
-
async function seamGithub (s, b) {
|
|
1651
|
-
if (!s.seamGithub) return { quilt: false }
|
|
1652
|
-
const repo = b && typeof b.repo === 'string' ? b.repo.trim() : ''
|
|
1653
|
-
if (repo && !(/^[\w.-]+\/[\w.-]+$/.test(repo) && /^\d+$/.test(String(b.installation || '')))) throw httpError(400, 'Pick a repository the Seam app reaches.')
|
|
1654
|
-
try { return await s.seamGithub(repo ? { repo, installation: String(b.installation) } : b && b.disconnect ? { disconnect: true } : {}) } catch (err) { throw httpError(err.status || 502, err.message) }
|
|
1655
|
-
}
|
|
1656
|
-
|
|
1657
1641
|
export async function squareTool (s, b) {
|
|
1658
1642
|
const tool = String((b && b.tool) || '')
|
|
1659
1643
|
if (tool === 'open_square') {
|
package/src/dev-servers.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
// Dev servers running from a session's folder on this computer, for the Preview tab: every program
|
|
2
|
-
// listening on a local TCP port whose working folder is the session's folder (or inside it), found
|
|
3
|
-
// with lsof. Nothing is found where lsof isn't (Windows): the tab still has its saved links.
|
|
4
|
-
import { execFile } from 'node:child_process'
|
|
5
|
-
import fs from 'node:fs'
|
|
6
|
-
import path from 'node:path'
|
|
7
|
-
|
|
8
|
-
const run = (args) => new Promise((resolve) => {
|
|
9
|
-
execFile('lsof', args, { timeout: 3000, maxBuffer: 4 * 1024 * 1024 }, (err, out) => resolve(err && !out ? '' : String(out || '')))
|
|
10
|
-
})
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* lsof's -F output as records: each `p<pid>` starts one, `c<command>` and `n<name>` lines fill it.
|
|
14
|
-
* Answers [{ pid, command, names: [] }].
|
|
15
|
-
*/
|
|
16
|
-
export function parseLsof (text) {
|
|
17
|
-
const out = []
|
|
18
|
-
let cur = null
|
|
19
|
-
for (const line of String(text || '').split('\n')) {
|
|
20
|
-
const tag = line[0]
|
|
21
|
-
const v = line.slice(1)
|
|
22
|
-
if (tag === 'p') { cur = { pid: Number(v), command: '', names: [] }; out.push(cur) } else if (cur && tag === 'c') cur.command = v
|
|
23
|
-
else if (cur && tag === 'n') cur.names.push(v)
|
|
24
|
-
}
|
|
25
|
-
return out
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/** The port of a listening socket's name ("*:3000", "127.0.0.1:5173", "[::1]:8080"), or 0. */
|
|
29
|
-
export function portOf (name) {
|
|
30
|
-
const m = /:(\d{2,5})$/.exec(String(name || ''))
|
|
31
|
-
return m ? Number(m[1]) : 0
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// A folder's real path (lsof reports them: on a Mac /var is /private/var), or the path as given.
|
|
35
|
-
const real = (p) => { try { return fs.realpathSync(p) } catch { return path.resolve(p) } }
|
|
36
|
-
|
|
37
|
-
/** Whether `cwd` is `dir` or inside it, comparing real paths. */
|
|
38
|
-
export function within (cwd, dir) {
|
|
39
|
-
const rel = path.relative(real(dir), real(cwd))
|
|
40
|
-
return rel === '' || (!rel.startsWith('..') && !path.isAbsolute(rel))
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* The dev servers running from `dir`: [{ port, url, command, pid }], lowest port first. `skip`: ports
|
|
45
|
-
* that are Quilt's own (its app), never listed.
|
|
46
|
-
*/
|
|
47
|
-
export async function devServers (dir, { skip = [] } = {}) {
|
|
48
|
-
if (process.platform === 'win32' || !dir) return []
|
|
49
|
-
const listening = parseLsof(await run(['-nP', '-iTCP', '-sTCP:LISTEN', '-Fpcn']))
|
|
50
|
-
if (!listening.length) return []
|
|
51
|
-
const cwds = new Map(parseLsof(await run(['-a', '-d', 'cwd', '-Fpn', '-p', listening.map((l) => l.pid).join(',')])).map((r) => [r.pid, r.names[0] || '']))
|
|
52
|
-
const seen = new Set()
|
|
53
|
-
const out = []
|
|
54
|
-
for (const l of listening) {
|
|
55
|
-
const cwd = cwds.get(l.pid)
|
|
56
|
-
if (!cwd || !within(cwd, dir)) continue
|
|
57
|
-
for (const n of l.names) {
|
|
58
|
-
const port = portOf(n)
|
|
59
|
-
if (!port || seen.has(port) || skip.includes(port)) continue
|
|
60
|
-
seen.add(port)
|
|
61
|
-
out.push({ port, url: `http://localhost:${port}`, command: l.command, pid: l.pid })
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return out.sort((a, b) => a.port - b.port)
|
|
65
|
-
}
|
package/src/ui/home-view.js
DELETED
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
// A workspace's home (plans/app-redesign.md, the dm06 mockup): charts of AI time and merges, its sessions as
|
|
2
|
-
// cards with who is working in each, and its previews (the links that matter). Drawn inside a session (its
|
|
3
|
-
// header's Home button) and as the workspace's own page. Data: the workspace (GET /api/workspaces/:id), its
|
|
4
|
-
// insights (AI minutes from the accounts API, merges from Seam) and this computer's open sessions.
|
|
5
|
-
import { esc, avatar, ago, I, api, toast, state, basename } from './common.js'
|
|
6
|
-
|
|
7
|
-
const SERIES = 'var(--chart, #2a78d6)' // one hue for every single-series chart
|
|
8
|
-
const DAY_MS = 24 * 60 * 60 * 1000
|
|
9
|
-
const dayStart = (t) => { const d = new Date(t); d.setHours(0, 0, 0, 0); return d.getTime() }
|
|
10
|
-
const hm = (min) => `${Math.floor(min / 60)}h ${String(Math.round(min % 60)).padStart(2, '0')}m`
|
|
11
|
-
|
|
12
|
-
/** The last `n` days (oldest first) with what fell on each: [{ start, label, value }]. */
|
|
13
|
-
function byDay (items, n, value = () => 1) {
|
|
14
|
-
const today = dayStart(Date.now())
|
|
15
|
-
const days = Array.from({ length: n }, (_, i) => ({ start: today - (n - 1 - i) * DAY_MS, value: 0 }))
|
|
16
|
-
for (const it of items) {
|
|
17
|
-
const i = days.findIndex((d) => it.at >= d.start && it.at < d.start + DAY_MS)
|
|
18
|
-
if (i >= 0) days[i].value += value(it)
|
|
19
|
-
}
|
|
20
|
-
return days.map((d, i) => ({ ...d, today: i === n - 1, label: new Date(d.start).toLocaleDateString([], { weekday: 'short' }) }))
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function aiChart (ins) {
|
|
24
|
-
const days = byDay(ins.aiHours || [], 7, (h) => h.minutes)
|
|
25
|
-
const total = days.reduce((a, d) => a + d.value, 0)
|
|
26
|
-
const prev = (ins.aiHours || []).filter((h) => h.at < days[0].start && h.at >= days[0].start - 7 * DAY_MS).reduce((a, h) => a + h.minutes, 0)
|
|
27
|
-
const max = Math.max(1, ...days.map((d) => d.value))
|
|
28
|
-
const change = prev ? Math.round(((total - prev) / prev) * 100) : null
|
|
29
|
-
return `<div class="hm-chart"><div class="hm-ch"><small>AI time · last 7 days</small><b>${hm(total)}</b>${change == null ? '<em>Counted from when Quilt started keeping it</em>' : `<em class="${change >= 0 ? 'up' : 'down'}">${change >= 0 ? '+' : ''}${change}% on the week before</em>`}</div>
|
|
30
|
-
<div class="hm-bars">${days.map((d) => `<div class="hm-bar${d.today ? ' today' : ''}" data-tip="${esc(`${d.today ? 'Today' : d.label} · ${hm(d.value)} of AI time`)}"><i style="height:${Math.max(2, (d.value / max) * 100).toFixed(1)}%"></i><span>${esc(d.label.slice(0, 3))}</span></div>`).join('')}</div></div>`
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function mergesChart (ins) {
|
|
34
|
-
const days = byDay(ins.merges || [], 14)
|
|
35
|
-
const week = days.slice(7).reduce((a, d) => a + d.value, 0)
|
|
36
|
-
const last = days.slice(0, 7).reduce((a, d) => a + d.value, 0)
|
|
37
|
-
const W = 280; const H = 90
|
|
38
|
-
const max = Math.max(1, ...days.map((d) => d.value))
|
|
39
|
-
const pts = days.map((d, i) => [i * W / (days.length - 1), H - 6 - (d.value / max) * (H - 16)])
|
|
40
|
-
const line = 'M' + pts.map(([x, y]) => `${x.toFixed(1)},${y.toFixed(1)}`).join(' L')
|
|
41
|
-
const dots = pts.map(([x, y], i) => `<span class="hm-dot" style="left:${(x / W * 100).toFixed(2)}%;top:${(y / H * 100).toFixed(2)}%" data-tip="${esc(`${i === days.length - 1 ? 'Today' : new Date(days[i].start).toLocaleDateString([], { month: 'short', day: 'numeric' })} · ${days[i].value} merge${days[i].value === 1 ? '' : 's'} onto main`)}"></span>`).join('')
|
|
42
|
-
const none = !(ins.merges || []).length
|
|
43
|
-
return `<div class="hm-chart"><div class="hm-ch"><small>Merged onto main · 14 days</small><b>${week} this week</b><em class="${none ? '' : week >= last ? 'up' : 'down'}">${none ? 'From its sessions in Seam open on this computer' : `${week >= last ? '+' : ''}${week - last} on last week`}</em></div>
|
|
44
|
-
<div class="hm-line"><svg viewBox="0 0 ${W} ${H}" preserveAspectRatio="none" aria-hidden="true"><path d="${line} L${W},${H} L0,${H} Z" fill="${SERIES}" fill-opacity=".10"/><path d="${line}" fill="none" stroke="${SERIES}" stroke-width="2" vector-effect="non-scaling-stroke" stroke-linejoin="round"/></svg>${dots}</div>
|
|
45
|
-
<div class="hm-ax"><span>2 weeks ago</span><span>Today</span></div></div>`
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function bySessionChart (ins, names) {
|
|
49
|
-
const since = dayStart(Date.now()) - 6 * DAY_MS
|
|
50
|
-
const per = new Map()
|
|
51
|
-
for (const h of ins.aiHours || []) if (h.at >= since) per.set(h.room, (per.get(h.room) || 0) + h.minutes)
|
|
52
|
-
const rows = [...per].sort((a, b) => b[1] - a[1]).slice(0, 5)
|
|
53
|
-
const max = Math.max(1, ...rows.map(([, v]) => v))
|
|
54
|
-
const top = rows.length ? Math.round(rows[0][1] / rows.reduce((a, [, v]) => a + v, 0) * 100) : 0
|
|
55
|
-
return `<div class="hm-chart"><div class="hm-ch"><small>AI time by session · 7 days</small><b>${rows.length} session${rows.length === 1 ? '' : 's'}</b><em>${rows.length ? `${esc(names.get(rows[0][0]) || rows[0][0])} is ${top}% of it` : 'No AI time yet this week'}</em></div>
|
|
56
|
-
<div class="hm-rows">${rows.map(([room, v]) => `<div class="hm-row" data-tip="${esc(`${names.get(room) || room} · ${hm(v)} of AI time this week`)}"><span class="hm-rn">${esc(names.get(room) || room)}</span><span class="hm-rt"><i style="width:${(v / max * 100).toFixed(1)}%"></i></span><span class="hm-rv">${hm(v)}</span></div>`).join('')}</div></div>`
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/** Who is working in each of the workspace's sessions open on this computer: room -> { working, faces, id }. */
|
|
60
|
-
function liveByRoom () {
|
|
61
|
-
const out = new Map()
|
|
62
|
-
for (const x of state.sessions.values()) {
|
|
63
|
-
const st = x.status
|
|
64
|
-
if (!st || !st.room) continue
|
|
65
|
-
const faces = [st.me, ...(st.peers || [])].filter((p) => p && p.agent && p.agent.status === 'working')
|
|
66
|
-
out.set(st.room, { id: x.id, working: faces.length, faces, people: [st.me, ...(st.peers || [])].filter(Boolean), name: st.sessionName || basename(x.dir) })
|
|
67
|
-
}
|
|
68
|
-
return out
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const facesHtml = (list, max = 4) => `<span class="hm-faces">${list.slice(0, max).map((p, i) => `<span style="z-index:${10 - i}">${avatar(p.name, p.color)}</span>`).join('')}</span>`
|
|
72
|
-
|
|
73
|
-
function sessionCard (s, live) {
|
|
74
|
-
const l = live.get(s.room)
|
|
75
|
-
const name = s.name || l?.name || s.room
|
|
76
|
-
const state = l ? (l.working ? `<span class="hm-cs lv"><span class="pulse"></span>${l.working} working</span>` : '<span class="hm-cs">Open here</span>') : `<span class="hm-cs">${s.lastActiveAt ? `Quiet · ${esc(ago(s.lastActiveAt))}` : 'Quiet'}</span>`
|
|
77
|
-
const doing = l ? (l.faces.map((p) => p.focus).find(Boolean) || '') : ''
|
|
78
|
-
return `<div class="hm-card${l && l.working ? '' : ' quiet'}" ${l ? `data-hm-open="${esc(l.id)}"` : `data-hm-join="${esc(s.room)}"`} title="${l ? 'Open this session' : 'Open it from the list below the cards'}">
|
|
79
|
-
<div class="hm-ct"><span class="hm-ico">${I.grid}</span><b>${esc(name)}</b>${state}</div>
|
|
80
|
-
<small class="hm-cl">${esc(doing || (l ? `${l.people.length} here` : 'Not open on this computer'))}</small>
|
|
81
|
-
<div class="hm-cf">${l ? facesHtml(l.working ? l.faces : l.people) : '<span></span>'}<span class="hm-room">${esc(name)}</span></div></div>`
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function previewsHtml (d, edit, names, adding) {
|
|
85
|
-
const links = d.links || []
|
|
86
|
-
const rows = links.map((l) => {
|
|
87
|
-
const host = (() => { try { return new URL(l.url).host } catch { return l.url } })()
|
|
88
|
-
const local = /^(localhost|127\.|0\.0\.0\.0)/.test(host)
|
|
89
|
-
return `<div class="hm-pv"><span class="hm-pvdot${local ? ' live' : ''}"></span><div class="hm-pvx"><b>${esc(l.name)}</b><code>${esc(host)}</code><small>${esc([l.room ? names.get(l.room) || '' : '', l.note].filter(Boolean).join(' · ') || 'For the whole workspace')}</small></div>
|
|
90
|
-
<a class="hm-pvo" href="${esc(l.url)}" target="_blank" rel="noopener" title="Open ${esc(l.url)}" aria-label="Open ${esc(l.name)}">${I.external}</a>${edit ? `<button type="button" class="hm-pvx-rm" data-hm-rmlink="${esc(l.id)}" title="Remove ${esc(l.name)}" aria-label="Remove ${esc(l.name)}">${I.x}</button>` : ''}</div>`
|
|
91
|
-
}).join('')
|
|
92
|
-
const form = adding
|
|
93
|
-
? `<form class="hm-pv hm-pvform" data-hm-linkform><input class="input" name="name" placeholder="Name (Production, Staging…)" required maxlength="80"><input class="input" name="url" placeholder="https://…" required maxlength="500"><select class="input" name="room"><option value="">Whole workspace</option>${(d.sessions || []).map((s) => `<option value="${esc(s.room)}">${esc(s.name || s.room)}</option>`).join('')}</select><button class="btn primary" type="submit">Add</button><button class="btn ghost" type="button" data-hm-cancel>Cancel</button></form>`
|
|
94
|
-
: edit ? `<button type="button" class="hm-pv hm-pvadd" data-hm-addlink>${I.plus}Add a link</button>` : ''
|
|
95
|
-
return `<section class="hm-sec"><h3>Previews</h3><div class="hm-pvg">${rows}${form}</div>${!links.length && !edit ? '<p class="hint">No links yet.</p>' : ''}</section>`
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/** The home's markup: `ins` may still be loading (null). */
|
|
99
|
-
export function workspaceHomeHtml (d, ins, { adding = false } = {}) {
|
|
100
|
-
const live = liveByRoom()
|
|
101
|
-
const names = new Map((d.sessions || []).map((s) => [s.room, s.name || live.get(s.room)?.name || s.room]))
|
|
102
|
-
const working = (d.sessions || []).reduce((a, s) => a + (live.get(s.room)?.working || 0), 0)
|
|
103
|
-
const busy = (d.sessions || []).filter((s) => live.get(s.room)?.working).length
|
|
104
|
-
const edit = d.access && (d.access.access === 'edit' || d.access.admin)
|
|
105
|
-
const charts = ins ? `<div class="hm-charts">${aiChart(ins)}${mergesChart(ins)}${bySessionChart(ins, names)}</div>` : '<div class="hm-charts loading"><div class="hm-chart"></div><div class="hm-chart"></div><div class="hm-chart"></div></div>'
|
|
106
|
-
return `<div class="hm-page">
|
|
107
|
-
<div class="hm-head"><div><h2>${esc(d.workspace.name)}</h2><small>${working ? `${working} working across ${busy} session${busy === 1 ? '' : 's'} right now` : `${(d.sessions || []).length} session${(d.sessions || []).length === 1 ? '' : 's'} · nobody working right now`}</small></div><span class="hm-sp"></span>
|
|
108
|
-
<button type="button" class="btn" data-hm-invite>${I.users}<span>Invite</span></button><button type="button" class="btn primary" data-hm-new>${I.plus}<span>New session</span></button></div>
|
|
109
|
-
${charts}
|
|
110
|
-
<section class="hm-sec"><h3>Sessions</h3><div class="hm-grid">${(d.sessions || []).map((s) => sessionCard(s, live)).join('') || '<p class="hint">No sessions yet: New session starts one.</p>'}</div></section>
|
|
111
|
-
${previewsHtml(d, edit, names, adding)}
|
|
112
|
-
</div>`
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const insights = new Map() // workspace id -> { at, data }
|
|
116
|
-
let loading = null
|
|
117
|
-
|
|
118
|
-
/** The workspace's insights, cached a minute: calls `then` when fresh ones arrive. */
|
|
119
|
-
export function homeInsights (id, then) {
|
|
120
|
-
const c = insights.get(id)
|
|
121
|
-
if (c && Date.now() - c.at < 60_000) return c.data
|
|
122
|
-
if (loading !== id) {
|
|
123
|
-
loading = id
|
|
124
|
-
api('GET', `/api/workspaces/${encodeURIComponent(id)}/insights`).then((data) => { insights.set(id, { at: Date.now(), data }); then() })
|
|
125
|
-
.catch(() => { insights.set(id, { at: Date.now(), data: { aiHours: [], merges: [] } }); then() })
|
|
126
|
-
.finally(() => { loading = null })
|
|
127
|
-
}
|
|
128
|
-
return c ? c.data : null
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
let tip = null
|
|
132
|
-
/** Clicks, the Add a link form and the charts' tooltips. `reload()` fetches the workspace again. */
|
|
133
|
-
export function bindWorkspaceHome (root, { id, go, reload, newSession, invite, setAdding }) {
|
|
134
|
-
if (!tip) { tip = document.createElement('div'); tip.className = 'hm-tip'; tip.hidden = true; document.body.appendChild(tip) }
|
|
135
|
-
root.onmousemove = (e) => {
|
|
136
|
-
const t = e.target.closest('[data-tip]')
|
|
137
|
-
if (!t || !root.contains(t)) { tip.hidden = true; return }
|
|
138
|
-
tip.textContent = t.dataset.tip
|
|
139
|
-
tip.hidden = false
|
|
140
|
-
tip.style.left = `${Math.min(e.clientX + 14, innerWidth - tip.offsetWidth - 8)}px`
|
|
141
|
-
tip.style.top = `${e.clientY - 34}px`
|
|
142
|
-
}
|
|
143
|
-
root.onmouseleave = () => { tip.hidden = true }
|
|
144
|
-
root.onclick = async (e) => {
|
|
145
|
-
const o = e.target.closest('[data-hm-open]')
|
|
146
|
-
if (o) { tip.hidden = true; go(o.dataset.hmOpen); return }
|
|
147
|
-
if (e.target.closest('[data-hm-join]')) { go(`ws:${id}`); return }
|
|
148
|
-
if (e.target.closest('[data-hm-new]')) return newSession()
|
|
149
|
-
if (e.target.closest('[data-hm-invite]')) return invite()
|
|
150
|
-
if (e.target.closest('[data-hm-addlink]')) { setAdding(true); return }
|
|
151
|
-
if (e.target.closest('[data-hm-cancel]')) { setAdding(false); return }
|
|
152
|
-
const rm = e.target.closest('[data-hm-rmlink]')
|
|
153
|
-
if (rm) {
|
|
154
|
-
try { await api('POST', `/api/workspaces/${encodeURIComponent(id)}/links/${encodeURIComponent(rm.dataset.hmRmlink)}/remove`) } catch (err) { toast(err.message) }
|
|
155
|
-
reload()
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
const form = root.querySelector('[data-hm-linkform]')
|
|
159
|
-
if (form) {
|
|
160
|
-
form.elements.name.focus()
|
|
161
|
-
form.onsubmit = async (e) => {
|
|
162
|
-
e.preventDefault()
|
|
163
|
-
try {
|
|
164
|
-
await api('POST', `/api/workspaces/${encodeURIComponent(id)}/links`, { name: form.elements.name.value, url: form.elements.url.value, room: form.elements.room.value || null })
|
|
165
|
-
setAdding(false)
|
|
166
|
-
reload()
|
|
167
|
-
} catch (err) { toast(err.message) }
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
}
|