heyquilt 0.3.187 → 0.3.188

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/src/ui/session.js CHANGED
@@ -28,6 +28,7 @@ import { renderCatchUp, bindCatchUp } from './catchup.js'
28
28
  import { heldCard } from './session-words.js'
29
29
  import { callButtonMarkup, callPinMarkup, screenStageMarkup, mountCall, unmountCall, renderCall, callCards, callCounts, callScope } from './voice.js'
30
30
  import { codeSideHtml, codeCrumbHtml, sideShut, toggleSideShut, toggleFolded } from './projects.js'
31
+ import { mountPreview } from './preview-page.js'
31
32
  import { dmThreads } from './project-model.js'
32
33
 
33
34
  let current = null // session id being shown
@@ -109,6 +110,9 @@ export function mountSession (id) {
109
110
  current = id
110
111
  // Opened from a channel or a direct message in the project's sidebar: on its chat.
111
112
  if (state.openChat === id) { ws(id).side = 'chat'; state.openChat = null }
113
+ // Opened from a preview's row under the codebase in the project's sidebar: on that preview.
114
+ // A preview left open when the codebase was last on screen is not opened again by itself: opening one starts a machine.
115
+ if (state.openPreview && state.openPreview.id === id) { ws(id).side = `preview:${state.openPreview.preview}`; state.openPreview = null } else if (String(ws(id).side || '').startsWith('preview:')) ws(id).side = ''
112
116
  pendingAssign = null
113
117
  resetLoom()
114
118
  boardQuery = '' // a search is for the board it was typed on
@@ -271,6 +275,7 @@ export function sessionUnmount () {
271
275
  pendingAssign = null
272
276
  unbindChanges()
273
277
  if (codeConns) { codeConns.destroy(); codeConns = null }
278
+ if (codePreview) { codePreview.destroy(); codePreview = null }
274
279
  current = null
275
280
  }
276
281
 
@@ -394,6 +399,8 @@ function bindMenu (btn, menu, onPick) {
394
399
  const pj = () => !!state.workspacesOn
395
400
  const projectHere = () => { const id = sum()?.workspace; return (id && (state.workspaces || []).find((w) => w.id === id)) || null }
396
401
  let codeConns = null // the Connections card while its page shows
402
+ let codePreview = null // a preview's page while it shows (preview-page.js)
403
+ const pvPick = new Map() // codebase -> { preview id: the branch you picked there }
397
404
 
398
405
  /** Under "Chat": who is in the conversation on screen. With the sidebar, a direct message is the two of you. */
399
406
  function chatSub (st) {
@@ -419,25 +426,41 @@ function renderCodeSide () {
419
426
  // So does the conversation on screen, before anything is written in it.
420
427
  if (side === 'chat' && state.to && !dms.some((t) => t.name === state.to)) dms.unshift({ name: state.to, ts: Date.now(), n: 0, call: 0 })
421
428
  if ($('#chat-sub')) $('#chat-sub').textContent = chatSub(st)
422
- el.innerHTML = codeSideHtml({ page, name: st.sessionName || basename(sum().dir), project: projectHere(), tasks: open, artifacts: (projectData()?.files || []).filter((f) => f.kind !== 'folder').length, chatNew, people, dms, dmOn: state.to || '', connections: !!state.connectionsOn, canInvite: !!st.access?.owner || st.access?.role !== 'viewer', call: calls.channel })
429
+ el.innerHTML = codeSideHtml({ page, name: st.sessionName || basename(sum().dir), project: projectHere(), tasks: open, artifacts: (projectData()?.files || []).filter((f) => f.kind !== 'folder').length, chatNew, people, dms, dmOn: state.to || '', connections: !!state.connectionsOn, canInvite: !!st.access?.owner || st.access?.role !== 'viewer', call: calls.channel, previews: state.previewsOn ? st.previews || [] : null, canEdit: st.access?.role !== 'viewer' })
423
430
  const root = $('#ws')
424
431
  root.dataset.sidePage = side
425
432
  $('#code-crumb').innerHTML = codeCrumbHtml(projectHere())
426
433
  // The pages drawn over the middle in their own box: Connections, and the project's Artifacts.
427
434
  // Drawn when the page changes, not every time the sidebar is: an artifact that is running stays as it is.
428
435
  const extra = $('#code-extra')
429
- const boxed = side === 'connections' || side === 'artifacts' ? side : ''
436
+ const boxed = side === 'connections' || side === 'artifacts' || side.startsWith('preview:') ? side : ''
430
437
  if ((extra.dataset.page || '') !== boxed) {
431
438
  if (codeConns) { codeConns.destroy(); codeConns = null }
439
+ if (codePreview) { codePreview.destroy(); codePreview = null }
432
440
  extra.innerHTML = ''
433
441
  extra.dataset.page = boxed
434
442
  extra.classList.toggle('pj-files', boxed === 'artifacts')
443
+ extra.classList.toggle('pv-view', boxed.startsWith('preview:'))
444
+ if (boxed.startsWith('preview:')) {
445
+ const id = current
446
+ if (!pvPick.has(id)) pvPick.set(id, {})
447
+ codePreview = mountPreview(extra, {
448
+ session: id,
449
+ id: boxed.slice('preview:'.length),
450
+ code: st.sessionName || basename(sum().dir),
451
+ status: () => (state.sessions.get(id) || sum()).status,
452
+ pick: pvPick.get(id),
453
+ // Added or changed: its own page. Removed, or no longer there: back to the Loom.
454
+ saved: (pid) => { ws(id).side = `preview:${pid}`; extra.dataset.page = ''; saveWs(id); renderCodeSide() },
455
+ gone: () => { if (current === id) showCodePage('loom') }
456
+ })
457
+ }
435
458
  if (boxed === 'connections') {
436
459
  extra.innerHTML = '<div class="files-head"><div class="t"><h2 class="crumbs">Connections</h2><p class="hint">Apps the agents in this codebase can use: its own, and the ones it gets from above. Agents never see the logins.</p></div></div><div data-code-connections></div>'
437
460
  codeConns = mountConnections(extra.querySelector('[data-code-connections]'), { type: 'session', id: st.room })
438
461
  }
439
462
  if (boxed === 'artifacts') { drawCodeArtifacts(); loadCodeArtifacts() }
440
- }
463
+ } else if (codePreview) codePreview.update()
441
464
  extra.hidden = !boxed
442
465
  }
443
466
 
package/src/ui-server.js CHANGED
@@ -22,7 +22,7 @@ import { migrateDir } from './legacy.js'
22
22
  import { writePrivateJson } from './private-file.js'
23
23
  import { autoToolFor } from './autowork-tools.js'
24
24
  import { workspaceMessages, sayInWorkspace, readWorkspaceMessages } from './account.js'
25
- import { readAccount, saveAccount, clearAccount, clearAccountIf, resumeAccount, startLink, waitForLink, signUpForLink, confirmSignUpForLink, fetchMe, signOut, revokeToken, accountFromProfile, renameSession, createAgentInvite, listAgents, agentDetails, listAccessTypes, listCollaborators, listGrants, putGrant, deleteGrant, inviteToSession, listSessionInvites, cancelSessionInvite, listWorkspaces, listOrgs, createWorkspace, getWorkspace, updateWorkspace, deleteWorkspace, putWorkspaceMember, removeWorkspaceMember, getAgentPlacement, putAgentPlacement, listOrgAgents, putWorkspaceAgent, deleteWorkspaceAgent, createWorkspaceAgentInvite, excludeSessionAgent, listExcludedSessionAgents, listSessionAgents, includeSessionAgent, setSessionWorkspace, moveSessionToWorkspace, listWorkspaceInvites, inviteToWorkspace, cancelWorkspaceInvite, listMyInvites, answerMyInvite, listMySessions, announceSessionStarted, announceWhenReported, listWorkspaceFiles, createWorkspaceFile, confirmWorkspaceFile, workspaceFileDownload, updateWorkspaceFile, deleteWorkspaceFile, createWorkspaceFolder, listWorkspaceFileVersions, listSandboxKeys, createSandboxKey, rotateSandboxKey, revokeSandboxKey, removeSandboxKey, aiVmFollow, aiVmUnfollow, aiVmStatus, aiVmConnect, aiVmUpdate, aiVmSignIn, aiVmWake, aiVmDisconnect, voiceIce, transcribeVoice, speakVoice, speakVoiceStream, apiUrl } from './account.js'
25
+ import { readAccount, saveAccount, clearAccount, clearAccountIf, resumeAccount, startLink, waitForLink, signUpForLink, confirmSignUpForLink, fetchMe, signOut, revokeToken, accountFromProfile, renameSession, createAgentInvite, listAgents, agentDetails, listAccessTypes, listCollaborators, listGrants, putGrant, deleteGrant, inviteToSession, listSessionInvites, cancelSessionInvite, listWorkspaces, listOrgs, createWorkspace, getWorkspace, updateWorkspace, deleteWorkspace, putWorkspaceMember, removeWorkspaceMember, getAgentPlacement, putAgentPlacement, listOrgAgents, putWorkspaceAgent, deleteWorkspaceAgent, createWorkspaceAgentInvite, excludeSessionAgent, listExcludedSessionAgents, listSessionAgents, includeSessionAgent, setSessionWorkspace, moveSessionToWorkspace, listWorkspaceInvites, inviteToWorkspace, cancelWorkspaceInvite, listMyInvites, answerMyInvite, listMySessions, announceSessionStarted, announceWhenReported, listWorkspaceFiles, createWorkspaceFile, confirmWorkspaceFile, workspaceFileDownload, updateWorkspaceFile, deleteWorkspaceFile, createWorkspaceFolder, listWorkspaceFileVersions, listSandboxKeys, createSandboxKey, rotateSandboxKey, revokeSandboxKey, removeSandboxKey, aiVmFollow, aiVmUnfollow, aiVmStatus, aiVmConnect, aiVmUpdate, aiVmSignIn, aiVmWake, aiVmDisconnect, voiceIce, transcribeVoice, speakVoice, speakVoiceStream, openPreview, apiUrl } from './account.js'
26
26
  import { aiName } from './persona.js'
27
27
  import { effectiveAccess, builtinType } from './session-access.js'
28
28
  import { cleanSessionName, BAD_SESSION_NAME, SESSION_NAME_MAX } from './session-name.js'
@@ -188,6 +188,7 @@ export const STATIC = {
188
188
  '/project-board.js': ['project-board.js', 'text/javascript; charset=utf-8'],
189
189
  '/project-pop.js': ['project-pop.js', 'text/javascript; charset=utf-8'],
190
190
  '/project-channel.js': ['project-channel.js', 'text/javascript; charset=utf-8'],
191
+ '/preview-page.js': ['preview-page.js', 'text/javascript; charset=utf-8'],
191
192
  '/prail.js': ['prail.js', 'text/javascript; charset=utf-8'],
192
193
  '/prail-model.js': ['prail-model.js', 'text/javascript; charset=utf-8'],
193
194
  '/rail-model.js': ['rail-model.js', 'text/javascript; charset=utf-8'],
@@ -236,6 +237,9 @@ const CSP = [
236
237
  "img-src 'self' data: https: https://www.google.com https://*.gstatic.com",
237
238
  "font-src 'self'",
238
239
  "connect-src 'self'",
240
+ // A codebase's preview, served by its preview machine (plans/previews.md): the one outside page the app frames.
241
+ // (and, in development, the same program on this computer).
242
+ "frame-src 'self' https://*.preview.heyquilt.com http://*.preview.localhost:*",
239
243
  "object-src 'none'",
240
244
  "base-uri 'none'",
241
245
  "form-action 'self'",
@@ -244,7 +248,7 @@ const CSP = [
244
248
 
245
249
  // preview: for development only (`quilt ui --preview`). Opening the bare address hands out the
246
250
  // link, so a dev preview pane can show the app. Any local page could then open it too.
247
- export async function startUi ({ port = 7420, onShutdown, preview = false, reporter, slowMs = 3000, keepOutMs = 3000 } = {}) {
251
+ export async function startUi ({ port = 7420, onShutdown, preview = false, reporter, slowMs = 3000, keepOutMs = 3000, previewOpenMs = 100 * 1000 } = {}) {
248
252
  // What this app tells Quilt about itself (see report.js). Off with the "report" setting.
249
253
  reporter = reporter || createReporter({ token: () => readAccount()?.token || null, enabled: () => getSettings().report !== false })
250
254
  // Body fields worth keeping with a route's outcome: which editor, which kind of start. Never free text.
@@ -630,6 +634,12 @@ export async function startUi ({ port = 7420, onShutdown, preview = false, repor
630
634
  return r.run.session
631
635
  }
632
636
 
637
+ /** `out`, with the codebase's status sent to the windows first: what was just changed is in it. */
638
+ const withStatus = (id, out) => { pushStatus(id); return out }
639
+ // Previews: the window says "still open" once a minute (preview-page.js); a codebase's timer here ends its looking when that stops.
640
+ const PREVIEW_OPEN_MS = previewOpenMs
641
+ const previewOpen = new Map() // codebase id -> the timer
642
+
633
643
  /**
634
644
  * The owner renames a session: on the relay, so everyone in it sees the new name, then on
635
645
  * heyquilt.com. Until the relay has reported a new session there (within a minute) the
@@ -1060,8 +1070,8 @@ export async function startUi ({ port = 7420, onShutdown, preview = false, repor
1060
1070
  try {
1061
1071
  const res = await fetch(`${apiUrl()}/v1/features`, { signal: AbortSignal.timeout(5000) })
1062
1072
  const f = res.ok ? await res.json() : {}
1063
- return { secrets: !!f.secrets, connections: !!f.connections, workspaces: !!f.workspaces && appWorkspaces() }
1064
- } catch { return { secrets: false, connections: false, workspaces: false } }
1073
+ return { secrets: !!f.secrets, connections: !!f.connections, workspaces: !!f.workspaces && appWorkspaces(), previews: !!f.previews }
1074
+ } catch { return { secrets: false, connections: false, workspaces: false, previews: false } }
1065
1075
  },
1066
1076
  'POST /api/secrets/env-scan': (b) => {
1067
1077
  const dirs = envDirs(b)
@@ -1216,6 +1226,28 @@ export async function startUi ({ port = 7420, onShutdown, preview = false, repor
1216
1226
  'POST /api/sessions/:id/stop': (b, id) => stop(id).then(() => ({ ok: true })),
1217
1227
  'POST /api/sessions/:id/say': (b, id) => get(id).say(b.text, { to: b.to || null }),
1218
1228
  'POST /api/sessions/:id/focus': (b, id) => { get(id).setFocus(b.text); return { ok: true } },
1229
+ // Previews (previews.js, plans/previews.md): the codebase's list is in its status; these add, change and remove one,
1230
+ // and say which one this window has open, on which branch (`id` null: none). For an app that is also told to the
1231
+ // accounts API, which makes or wakes the codebase's preview machine and answers with where it is and a ticket;
1232
+ // the window asks again each minute while the preview stays open.
1233
+ 'POST /api/sessions/:id/previews': (b, id) => withStatus(id, { preview: get(id).savePreview({ ...(b.id ? { id: String(b.id) } : {}), ...(b.name !== undefined ? { name: b.name } : {}), ...(b.kind !== undefined ? { kind: b.kind } : {}), ...(b.command !== undefined ? { command: b.command } : {}), ...(b.folder !== undefined ? { folder: b.folder } : {}), ...(b.port !== undefined ? { port: Number(b.port) || 0 } : {}), ...(b.url !== undefined ? { url: b.url } : {}) }) }),
1234
+ 'POST /api/sessions/:id/previews/remove': (b, id) => withStatus(id, { ok: get(id).removePreview(String(b.id || '')) }),
1235
+ 'POST /api/sessions/:id/previews/open': async (b, id) => {
1236
+ const s = get(id)
1237
+ const def = b && b.id ? s.previews().find((p) => p.id === b.id && p.kind === 'app') : null
1238
+ s.lookAtPreview(def ? { id: def.id, branch: b.branch, again: b.again } : null)
1239
+ // A window that was closed, or left the page, without saying so: nobody is looking once it has stopped asking.
1240
+ clearTimeout(previewOpen.get(id))
1241
+ previewOpen.delete(id)
1242
+ if (!def) return { open: null }
1243
+ const gone = setTimeout(() => { previewOpen.delete(id); try { runs.get(id)?.run.session.lookAtPreview(null) } catch {} }, PREVIEW_OPEN_MS)
1244
+ gone.unref?.()
1245
+ previewOpen.set(id, gone)
1246
+ const open = await asAccount((token) => openPreview({ token, room: s.room }))
1247
+ // Development: a preview machine's program running on this computer (http://<machine>-<slot>.preview.localhost:<port>).
1248
+ const local = Number(process.env.QUILT_PREVIEW_LOCAL_PORT) || 0
1249
+ return { open: local && /\.localhost$/.test(String(open.domain)) ? { ...open, port: local } : open }
1250
+ },
1219
1251
  // Voice (voice.js): the call as this app sees it, and our part in it, from the app window, which does the audio.
1220
1252
  // `?to=<name>`: the call with that person alone (a direct message's), instead of the codebase's.
1221
1253
  'GET /api/sessions/:id/voice': (b, id, url) => callView(get(id), url.searchParams.get('to') || ''),