Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/app/src/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,12 @@ ${[["linear","Linear","Issues and projects"],["clickup","ClickUp","Tasks and lis
<dialog id="exe-setup" aria-labelledby="exe-setup-title" class="w-[min(42rem,calc(100%-2rem))] rounded-2xl border border-stone-200 bg-white p-0 text-slate-950 shadow-2xl backdrop:bg-slate-950/60 dark:border-slate-700 dark:bg-slate-900 dark:text-white"><div class="p-6"><div class="flex items-start justify-between gap-4"><div><h2 id="exe-setup-title" class="text-lg font-semibold">Connect Exe.dev</h2><p class="mt-1 text-sm text-slate-500 dark:text-slate-400">This saves a write-only token and adds the VM as an execution target.</p></div><button type="button" data-close-setup="exe" aria-label="Close Exe.dev setup" class="min-h-11 px-2 text-sm font-semibold text-slate-500">Close</button></div><form id="connection" class="mt-6 grid gap-4 sm:grid-cols-2"><label class="label">SSH destination<input class="field" name="vmName" required placeholder="exedev@workbox"></label><label class="label">Restricted HTTPS token<input class="field" type="password" name="apiToken" required autocomplete="new-password" placeholder="Enter a new token"></label><label class="label sm:col-span-2">Working directory<input class="field" name="cwd" required placeholder="/home/exedev/project"></label><label class="label">Agent<select class="field" name="agentKind"><option value="codex">Codex</option><option value="claude">Claude</option></select></label><div class="flex items-end"><button type="submit" class="min-h-11 rounded-xl bg-slate-950 px-4 text-sm font-semibold text-white dark:bg-white dark:text-slate-950">Save connection</button></div></form><p id="settings-message" role="status" class="mt-4 text-sm"></p></div></dialog>
<dialog id="amp-setup" aria-labelledby="amp-setup-title" class="w-[min(42rem,calc(100%-2rem))] rounded-2xl border border-stone-200 bg-white p-0 text-slate-950 shadow-2xl backdrop:bg-slate-950/60 dark:border-slate-700 dark:bg-slate-900 dark:text-white"><div class="p-6"><div class="flex items-start justify-between gap-4"><div><h2 id="amp-setup-title" class="text-lg font-semibold">Connect Amp</h2><p class="mt-1 text-sm text-slate-500 dark:text-slate-400">This verifies and stores a write-only token for an Amp cloud project.</p></div><button type="button" data-close-setup="amp" class="min-h-11 px-2 text-sm font-semibold text-slate-500">Close</button></div><form id="amp-connection" class="mt-6 grid gap-4 sm:grid-cols-2"><label class="label">Amp project<input class="field" name="project" required placeholder="owner/repository"></label><label class="label">Amp access token<input class="field" type="password" name="accessToken" required autocomplete="new-password" placeholder="Enter a new token"></label><label class="label sm:col-span-2">Cloud API base URL<input class="field" type="url" name="apiBaseUrl" value="https://ampcode.com/api/cloud/v1" required></label><div><button type="button" id="test-amp" class="min-h-11 rounded-xl border border-stone-300 px-4 text-sm font-semibold">Test new connection</button></div><div><button type="submit" class="min-h-11 rounded-xl bg-slate-950 px-4 text-sm font-semibold text-white dark:bg-white dark:text-slate-950">Save connection</button></div></form><p id="amp-message" role="status" class="mt-4 text-sm"></p></div></dialog>
<dialog id="tail-setup" aria-labelledby="tail-setup-title" class="w-[min(42rem,calc(100%-2rem))] rounded-2xl border border-stone-200 bg-white p-0 text-slate-950 shadow-2xl backdrop:bg-slate-950/60 dark:border-slate-700 dark:bg-slate-900 dark:text-white"><div class="p-6"><div class="flex items-start justify-between gap-4"><div><h2 id="tail-setup-title" class="text-lg font-semibold">Install Cloudflare Tail</h2><p class="mt-1 text-sm text-slate-500 dark:text-slate-400">Name the installation and paste a secret, or have Factorize generate one.</p></div><button type="button" data-close-setup="tail" class="min-h-11 px-2 text-sm font-semibold text-slate-500">Close</button></div><form id="tail-connection" class="mt-6 grid gap-4 sm:grid-cols-2"><label class="label">Installation name<input class="field" name="name" required maxlength="120" placeholder="Production Workers"></label><label class="label">Signing secret<input class="field" type="password" name="signingSecret" minlength="16" autocomplete="new-password" placeholder="Paste a secret, or generate one"></label><label class="flex min-h-11 items-center gap-2 text-sm"><input type="checkbox" name="generateSecret"> Generate a strong secret</label><div><button type="submit" class="min-h-11 rounded-xl bg-slate-950 px-4 text-sm font-semibold text-white dark:bg-white dark:text-slate-950">Install Tail</button></div></form><div id="tail-generated" class="mt-4 hidden rounded-lg bg-amber-50 p-4 text-slate-950"><p class="text-sm font-semibold">Copy this secret now</p><div class="mt-2 flex gap-2"><code id="tail-generated-value" class="min-w-0 flex-1 overflow-x-auto"></code><button id="copy-tail-secret" type="button" class="rounded-lg border px-3 py-2 text-sm font-semibold">Copy</button></div></div><p id="tail-message" role="status" class="mt-4 text-sm"></p></div></dialog>
<section class="mt-12" aria-labelledby="installed-integrations-title"><div><h2 id="installed-integrations-title" class="text-xl font-semibold">Installed integrations</h2><p class="mt-1 text-sm text-slate-500 dark:text-slate-400">Check status and manage providers already connected to Factorize.</p></div><div id="installed-loading" class="${card} mt-5 p-6 text-sm text-slate-500" role="status">Loading installed integrations…</div><div id="installed-empty" class="${card} mt-5 hidden p-8 text-center"><h3 class="font-semibold">No integrations installed</h3><p class="mt-2 text-sm text-slate-500">Choose an available provider above to get started.</p></div><div id="installed-table" class="mt-5 hidden rounded-2xl border border-stone-200 bg-white shadow-sm dark:border-slate-800 dark:bg-slate-900"><table class="w-full text-left"><thead class="hidden bg-stone-50 text-xs font-semibold uppercase tracking-wide text-slate-500 sm:table-header-group dark:bg-slate-950/50 dark:text-slate-400"><tr><th scope="col" class="px-5 py-3">Integration</th><th scope="col" class="px-5 py-3">Details</th><th scope="col" class="px-5 py-3">Status</th><th scope="col" class="px-5 py-3 text-right">Actions</th></tr></thead><tbody id="installed-integrations" class="block divide-y divide-stone-200 sm:table-row-group dark:divide-slate-800"></tbody></table></div></section>`), `${uiHelpers}
<section class="mt-12" aria-labelledby="installed-integrations-title"><div><h2 id="installed-integrations-title" class="text-xl font-semibold">Installed integrations</h2><p class="mt-1 text-sm text-slate-500 dark:text-slate-400">Check status and manage providers already connected to Factorize.</p></div><div id="installed-loading" class="${card} mt-5 p-6 text-sm text-slate-500" role="status">Loading installed integrations…</div><div id="installed-empty" class="${card} mt-5 hidden p-8 text-center"><h3 class="font-semibold">No integrations installed</h3><p class="mt-2 text-sm text-slate-500">Choose an available provider above to get started.</p></div><div id="installed-table" class="mt-5 hidden grid gap-3 sm:grid-cols-2"><div id="installed-integrations" class="contents"></div></div></section>`), `${uiHelpers}
const badge=(id,label,tone)=>{const el=$(id);el.textContent=label;el.className='text-xs font-medium '+(tone==='warn'?'text-amber-700 dark:text-amber-300':'text-slate-500 dark:text-slate-400')};
const integrationIcons=${JSON.stringify(integrationIcons)};
const testButton=(kind,id)=>'<button type="button" data-test="'+kind+'" data-id="'+esc(id)+'" class="rounded-lg border border-stone-300 px-3 py-1.5 text-xs font-semibold">Test</button>'+(kind==='exe'?refreshModelsButton(id):'');
const refreshModelsButton=id=>'<button type="button" data-refresh-models="'+esc(id)+'" class="rounded-lg border border-stone-300 px-3 py-1.5 text-xs font-semibold">Refresh models</button>';
const installedRow=(name,description,status,tone,actions)=>'<tr class="block p-5 sm:table-row sm:p-0"><th scope="row" class="pb-3 text-left sm:px-5 sm:py-4"><span class="flex items-center gap-2.5"><span class="flex h-7 w-7 shrink-0 items-center justify-center text-slate-800 dark:text-slate-100">'+integrationIcons[name==='Cloudflare Tail'?'tail':name==='Exe.dev'?'exe':name.toLowerCase()]+'</span><span class="font-semibold">'+esc(name)+'</span></span></th><td class="block break-words pb-3 text-sm text-slate-500 sm:table-cell sm:px-5 sm:py-4 dark:text-slate-400"><span class="mb-1 block text-xs font-semibold uppercase tracking-wide text-slate-400 sm:hidden">Details</span>'+description+'</td><td class="block pb-4 sm:table-cell sm:px-5 sm:py-4"><span class="rounded-full px-2.5 py-1 text-xs font-semibold '+(tone==='ok'?'bg-green-100 text-green-800 dark:bg-green-950 dark:text-green-200':'bg-amber-100 text-amber-800 dark:bg-amber-950 dark:text-amber-200')+'">'+esc(status)+'</span></td><td class="block text-right sm:table-cell sm:px-5 sm:py-4"><details class="relative inline-block text-left"><summary class="inline-flex min-h-9 cursor-pointer list-none items-center gap-1.5 rounded-lg border border-stone-300 bg-white px-3 py-1.5 text-xs font-semibold hover:bg-stone-50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-factorize-600 dark:border-slate-700 dark:bg-slate-900 dark:hover:bg-slate-800 [&::-webkit-details-marker]:hidden">Actions<svg aria-hidden="true" viewBox="0 0 16 16" class="h-3.5 w-3.5" fill="none" stroke="currentColor" stroke-width="1.75"><path d="m4 6 4 4 4-4" stroke-linecap="round" stroke-linejoin="round"/></svg></summary><div class="absolute right-0 z-20 mt-1 flex min-w-36 flex-col gap-1 rounded-xl border border-stone-200 bg-white p-1.5 shadow-lg dark:border-slate-700 dark:bg-slate-900 [&>a]:w-full [&>button]:w-full">'+actions+'</div></details></td></tr>';
const installedRow=(name,description,status,tone,actions)=>'<article class="relative rounded-2xl border border-stone-200 bg-white p-5 shadow-sm dark:border-slate-800 dark:bg-slate-900"><div class="flex items-start justify-between gap-4"><div class="flex min-w-0 items-center gap-2.5"><span class="flex h-7 w-7 shrink-0 items-center justify-center text-slate-800 dark:text-slate-100">'+integrationIcons[name==='Cloudflare Tail'?'tail':name==='Exe.dev'?'exe':name.toLowerCase()]+'</span><h3 class="break-words font-semibold">'+esc(name)+'</h3></div><details class="relative shrink-0 text-left"><summary class="inline-flex min-h-9 cursor-pointer list-none items-center gap-1.5 rounded-lg border border-stone-300 bg-white px-3 py-1.5 text-xs font-semibold hover:bg-stone-50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-factorize-600 dark:border-slate-700 dark:bg-slate-900 dark:hover:bg-slate-800 [&::-webkit-details-marker]:hidden">Actions<svg aria-hidden="true" viewBox="0 0 16 16" class="h-3.5 w-3.5" fill="none" stroke="currentColor" stroke-width="1.75"><path d="m4 6 4 4 4-4" stroke-linecap="round" stroke-linejoin="round"/></svg></summary><div class="absolute right-0 z-20 mt-1 flex min-w-36 flex-col gap-1 rounded-xl border border-stone-200 bg-white p-1.5 shadow-lg dark:border-slate-700 dark:bg-slate-900 [&>a]:w-full [&>button]:w-full">'+actions+'</div></details></div><p class="mt-4 break-words text-sm text-slate-500 dark:text-slate-400">'+description+'</p><span class="mt-4 inline-flex rounded-full px-2.5 py-1 text-xs font-semibold '+(tone==='ok'?'bg-green-100 text-green-800 dark:bg-green-950 dark:text-green-200':'bg-amber-100 text-amber-800 dark:bg-amber-950 dark:text-amber-200')+'">'+esc(status)+'</span></article>';
async function disconnectGitHub(id){if(!confirm('Disconnect this GitHub installation from Factorize?'))return;await request('/api/github/installations/'+encodeURIComponent(id),{method:'DELETE'});await load()}
async function load(){const loading=$('#installed-loading'),list=$('#installed-integrations'),table=$('#installed-table'),empty=$('#installed-empty');loading.classList.remove('hidden');table.classList.add('hidden');empty.classList.add('hidden');$('#integration-error').classList.add('hidden');try{const [s,gh,tails]=await Promise.all([request('/api/connections/status'),fetch('/api/github/installations'),request('/api/connections/cloudflare-tail')]),rows=[];const exe=s.exeConnections||[],amps=s.ampConnections||[];badge('#linear-available-status',(s.linear?1:0)+' installed','neutral');badge('#clickup-available-status',(s.clickup?1:0)+' installed','neutral');badge('#exe-available-status',exe.length+' installed','neutral');badge('#amp-available-status',amps.length+' installed','neutral');badge('#tail-available-status',tails.length+' installed','neutral');$('#linear-action').textContent=s.linear?'Reconnect Linear':'Continue to Linear';if(s.linear)rows.push(installedRow('Linear',esc(s.linear.organizationName||'Linear workspace')+(s.linear.viewerEmail?' · '+esc(s.linear.viewerEmail):''),'Connected','ok','<button type="button" data-open-setup="linear" class="rounded-lg border border-stone-300 px-3 py-2 text-xs font-semibold">Reconnect</button>'));if(s.clickup)rows.push(installedRow('ClickUp',esc(s.clickup.teamName||'ClickUp workspace'),'Connected','ok','<button type="button" data-open-setup="clickup" class="rounded-lg border border-stone-300 px-3 py-2 text-xs font-semibold">Reconnect</button>'));exe.forEach(c=>rows.push(installedRow('Exe.dev',esc(c.vmName)+' · '+esc(c.cwd)+' · '+esc(c.agentKind),'Connected','ok',testButton('exe',c.connectionId)+'<button type="button" data-open-setup="exe" class="rounded-lg border border-stone-300 px-3 py-2 text-xs font-semibold">Add another</button>')));amps.forEach(c=>rows.push(installedRow('Amp',esc(c.project),'Connected','ok',testButton('amp',c.connectionId)+'<button type="button" data-open-setup="amp" class="rounded-lg border border-stone-300 px-3 py-2 text-xs font-semibold">Add another</button>')));tails.forEach(c=>rows.push(installedRow('Cloudflare Tail',esc(c.name)+(c.referencedJobCount?' · '+c.referencedJobCount+' jobs':''),'Connected','ok','<button type="button" data-test-tail="'+esc(c.integrationId)+'" class="rounded-lg border border-stone-300 px-3 py-2 text-xs font-semibold">Test</button><button type="button" data-configure-tail="'+esc(c.integrationId)+'" data-name="'+esc(c.name)+'" class="rounded-lg border border-stone-300 px-3 py-2 text-xs font-semibold">Configure</button><button type="button" data-disconnect-tail="'+esc(c.integrationId)+'" class="rounded-lg border border-red-200 px-3 py-2 text-xs font-semibold text-red-700 dark:border-red-900 dark:text-red-300">Disconnect</button>')));if(gh.status===404){badge('#github-available-status','Unavailable','neutral');$('#github-install').classList.add('hidden')}else if(!gh.ok){badge('#github-available-status','Action required','warn');rows.push(installedRow('GitHub','Installation status could not be loaded.','Action required','warn','<button type="button" data-open-setup="github" class="rounded-lg border border-stone-300 px-3 py-2 text-xs font-semibold">Reconnect</button>'))}else{const installs=await gh.json(),active=installs.filter(x=>x.state==='active');badge('#github-available-status',active.length+' installed',installs.length&&!active.length?'warn':'neutral');$('#github-install').textContent=active.length?'Add another installation':'Continue to GitHub';installs.forEach(x=>rows.push(installedRow('GitHub',esc(x.accountLogin||'Installation '+x.installationId)+' · '+esc(x.accountType||'GitHub'),x.state==='active'?'Connected':x.state,'active'===x.state?'ok':'warn','<a href="https://github.com/settings/installations" target="_blank" rel="noreferrer" class="rounded-lg border border-stone-300 px-3 py-2 text-xs font-semibold">Configure ↗</a><button type="button" data-disconnect-github="'+esc(x.installationId)+'" class="rounded-lg border border-red-200 px-3 py-2 text-xs font-semibold text-red-700 dark:border-red-900 dark:text-red-300">Disconnect</button>')))}list.innerHTML=rows.join('');loading.classList.add('hidden');table.classList.toggle('hidden',!rows.length);empty.classList.toggle('hidden',rows.length>0);bindActions()}catch(e){loading.classList.add('hidden');empty.classList.remove('hidden');const error=$('#integration-error');error.textContent=e.message||'Could not load integration status. Try again.';error.classList.remove('hidden');['linear','clickup','github','exe','amp','tail'].forEach(id=>badge('#'+id+'-available-status','Unavailable','neutral'))}}
function openSetup(kind){const dialog=$('#'+kind+'-setup');if(!dialog.open)dialog.showModal()}
Expand Down
13 changes: 6 additions & 7 deletions packages/app/test/ui.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,14 @@ describe("pages", () => {
expect(settings).toContain('data-disconnect-github=');
expect(settings).toContain("Reconnect");
expect(settings).toContain("Configure");
expect(settings).toContain('<table class="w-full text-left">');
expect(settings).toContain('<th scope="col" class="px-5 py-3">Integration</th>');
expect(settings).toContain('<tbody id="installed-integrations"');
expect(settings).toContain('<th scope="row"');
expect(settings).toContain("sm:table-row");
expect(settings).toContain('<span class="flex items-center gap-2.5">');
expect(settings).toContain('id="installed-table" class="mt-5 hidden grid gap-3 sm:grid-cols-2"');
expect(settings).toContain('<div id="installed-integrations" class="contents"');
expect(settings).toContain('<article class="relative rounded-2xl');
expect(settings).toContain('flex items-start justify-between gap-4');
expect(settings).toContain('<div class="flex min-w-0 items-center gap-2.5">');
expect(settings).toContain('<span class="flex h-7 w-7 shrink-0 items-center justify-center text-slate-800');
expect(settings).not.toContain("h-10 w-10 shrink-0 items-center justify-center rounded-xl border");
expect(settings).toContain('<details class="relative inline-block text-left">');
expect(settings).toContain('<details class="relative shrink-0 text-left">');
expect(settings).toContain("Actions<svg aria-hidden=\"true\"");
expect(settings).toContain("absolute right-0 z-20");
expect(settings).toContain("const form=e.currentTarget,d=new FormData(form)");
Expand Down