-${[["linear","Linear","Issues and projects"],["github","GitHub","Repositories and triggers"],["exe","Exe.dev","VM execution"],["amp","Amp","Cloud execution"],["tail","Cloudflare Tail","Signed Worker Tail events"]].map(([id,name,description])=>`
${name}
Checking…${description}
${id==="linear"?`Connect Linear →`:id==="github"?`Install GitHub App →`:``}`).join("")}
+
Available integrations
Choose a provider to review setup before anything changes.
+${[["linear","Linear","Issues and projects"],["github","GitHub","Repositories and triggers"],["exe","Exe.dev","VM execution"],["amp","Amp","Cloud execution"],["tail","Cloudflare Tail","Signed Worker Tail events"]].map(([id,name,description])=>`
`).join("")}
-
Connect Exe.dev
Add a VM destination and working directory.
-
Connect Amp
Add a cloud project as an execution target.
-
Install Cloudflare Tail
Use a separate signing secret for each installation.
+
+
+
+
+
Installed integrations
Check status and manage providers already connected to Factorize.
Loading installed integrations…
No integrations installed
Choose an available provider above to get started.
`), `${uiHelpers}
-const badge=(id,label,tone)=>{const el=$(id);el.textContent=label;el.className='rounded-full px-3 py-1 text-xs font-semibold '+(tone==='ok'?'bg-green-100 text-green-800 dark:bg-green-950 dark:text-green-200':tone==='warn'?'bg-amber-100 text-amber-800 dark:bg-amber-950 dark:text-amber-200':'bg-stone-100 text-slate-600 dark:bg-slate-800 dark:text-slate-300')};
+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 testButton=(kind,id)=>'
';
const installedRow=(name,description,status,tone,actions)=>'
'+esc(name)+'
'+esc(status)+''+description+'
'+actions+'
';
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'),empty=$('#installed-empty');loading.classList.remove('hidden');list.classList.add('hidden');empty.classList.add('hidden');$('#integration-error').classList.add('hidden');try{const [s,gh]=await Promise.all([request('/api/connections/status'),fetch('/api/github/installations')]),rows=[];const exe=s.exeConnections||[],amps=s.ampConnections||[];badge('#linear-available-status',s.linear?'Connected':'Available',s.linear?'ok':'neutral');badge('#exe-available-status',exe.length?'Connected':'Available',exe.length?'ok':'neutral');badge('#amp-available-status',amps.length?'Connected':'Available',amps.length?'ok':'neutral');$('#linear-action').textContent=s.linear?'Reconnect →':'Connect Linear →';if(s.linear)rows.push(installedRow('Linear',esc(s.linear.organizationName||'Linear workspace')+(s.linear.viewerEmail?' · '+esc(s.linear.viewerEmail):''),'Connected','ok','
Reconnect'));exe.forEach(c=>rows.push(installedRow('Exe.dev',esc(c.vmName)+' · '+esc(c.cwd)+' · '+esc(c.agentKind),'Connected','ok',testButton('exe',c.connectionId)+'
')));amps.forEach(c=>rows.push(installedRow('Amp',esc(c.project),'Connected','ok',testButton('amp',c.connectionId)+'
')));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','
Reconnect'))}else{const installs=await gh.json(),active=installs.filter(x=>x.state==='active');badge('#github-available-status',active.length?'Connected':installs.length?'Action required':'Available',active.length?'ok':installs.length?'warn':'neutral');$('#github-install').textContent=active.length?'Add installation →':'Install GitHub App →';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','
Configure ↗')))}list.innerHTML=rows.join('');loading.classList.add('hidden');list.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','github','exe','amp'].forEach(id=>badge('#'+id+'-available-status','Unavailable','neutral'))}}
-function openSetup(kind){const panel=$('#'+kind+'-setup');panel.classList.remove('hidden');panel.scrollIntoView({behavior:'smooth',block:'start'})}
-function bindActions(){bindTests();document.querySelectorAll('[data-open-setup]').forEach(button=>button.onclick=()=>openSetup(button.dataset.openSetup));document.querySelectorAll('[data-close-setup]').forEach(button=>button.onclick=()=>$('#'+button.dataset.closeSetup+'-setup').classList.add('hidden'));document.querySelectorAll('[data-disconnect-github]').forEach(button=>button.onclick=()=>disconnectGitHub(button.dataset.disconnectGithub).catch(e=>{const error=$('#integration-error');error.textContent=e.message;error.classList.remove('hidden')}))}
+async function load(){const loading=$('#installed-loading'),list=$('#installed-integrations'),empty=$('#installed-empty');loading.classList.remove('hidden');list.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('#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','
'));exe.forEach(c=>rows.push(installedRow('Exe.dev',esc(c.vmName)+' · '+esc(c.cwd)+' · '+esc(c.agentKind),'Connected','ok',testButton('exe',c.connectionId)+'
')));amps.forEach(c=>rows.push(installedRow('Amp',esc(c.project),'Connected','ok',testButton('amp',c.connectionId)+'
')));tails.forEach(c=>rows.push(installedRow('Cloudflare Tail',esc(c.name)+(c.referencedJobCount?' · '+c.referencedJobCount+' jobs':''),'Connected','ok','
')));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','
'))}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','
Configure ↗')))}list.innerHTML=rows.join('');loading.classList.add('hidden');list.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','github','exe','amp','tail'].forEach(id=>badge('#'+id+'-available-status','Unavailable','neutral'))}}
+function openSetup(kind){const dialog=$('#'+kind+'-setup');if(!dialog.open)dialog.showModal()}
+function closeSetup(kind){const dialog=$('#'+kind+'-setup');if(dialog.open)dialog.close()}
+async function tailAction(id,method){await request('/api/connections/cloudflare-tail/'+encodeURIComponent(id),{method});await load()}
+function bindActions(){bindTests();document.querySelectorAll('[data-open-setup]').forEach(button=>button.onclick=()=>{if(button.dataset.openSetup==='tail'){delete $('#tail-connection').dataset.id;$('#tail-connection').reset()}openSetup(button.dataset.openSetup)});document.querySelectorAll('[data-close-setup]').forEach(button=>button.onclick=()=>closeSetup(button.dataset.closeSetup));document.querySelectorAll('dialog').forEach(dialog=>dialog.onclick=e=>{if(e.target===dialog)dialog.close()});document.querySelectorAll('[data-disconnect-github]').forEach(button=>button.onclick=()=>disconnectGitHub(button.dataset.disconnectGithub).catch(showError));document.querySelectorAll('[data-disconnect-tail]').forEach(button=>button.onclick=()=>{if(confirm('Disconnect this Tail installation? Jobs using it will need another installation.'))tailAction(button.dataset.disconnectTail,'DELETE').catch(showError)});document.querySelectorAll('[data-test-tail]').forEach(button=>button.onclick=async()=>{button.disabled=true;try{await request('/api/connections/cloudflare-tail/'+encodeURIComponent(button.dataset.testTail)+'/test',{method:'POST'});button.textContent='Connected'}catch(e){button.textContent='Action required'}finally{button.disabled=false}});document.querySelectorAll('[data-configure-tail]').forEach(button=>button.onclick=()=>{const form=$('#tail-connection');form.dataset.id=button.dataset.configureTail;form.elements.name.value=button.dataset.name;openSetup('tail')})}
+function showError(e){const error=$('#integration-error');error.textContent=e.message||'The integration action failed.';error.classList.remove('hidden')}
function bindTests(){document.querySelectorAll('[data-test]').forEach(button=>button.onclick=async()=>{const original=button.textContent;button.disabled=true;button.textContent='Testing…';try{const kind=button.dataset.test,result=await request('/api/connections/'+kind+'/test',{method:'POST',headers:{'content-type':'application/json'},body:JSON.stringify({connectionId:button.dataset.id})});button.textContent=result.ok?'Connected':'Action required'}catch(e){button.textContent='Action required'}finally{setTimeout(()=>{button.disabled=false;button.textContent=original},1500)}})}
$('#connection').onsubmit=async e=>{e.preventDefault();const d=new FormData(e.currentTarget),m=$('#settings-message');try{await request('/api/connections/exe',{method:'PUT',headers:{'content-type':'application/json'},body:JSON.stringify({vmName:d.get('vmName'),apiToken:d.get('apiToken'),cwd:d.get('cwd'),agentKind:d.get('agentKind'),herdrCommand:'herdr',agentCommand:''})});e.currentTarget.reset();m.textContent='Connection saved. The token remains write-only.';await load()}catch(x){m.textContent=x.message}};
const ampPayload=()=>{const d=new FormData($('#amp-connection'));return {project:d.get('project'),accessToken:d.get('accessToken'),apiBaseUrl:d.get('apiBaseUrl')}};$('#test-amp').onclick=async()=>{const m=$('#amp-message');try{const x=await request('/api/connections/amp/test',{method:'POST',headers:{'content-type':'application/json'},body:JSON.stringify(ampPayload())});m.textContent=x.ok?'Amp connection succeeded.':'Amp connection needs attention.'}catch(x){m.textContent=x.message}};$('#amp-connection').onsubmit=async e=>{e.preventDefault();const m=$('#amp-message');try{await request('/api/connections/amp',{method:'PUT',headers:{'content-type':'application/json'},body:JSON.stringify(ampPayload())});e.currentTarget.reset();m.textContent='Amp connection saved. The token remains write-only.';await load()}catch(x){m.textContent=x.message}};
-$('#tail-connection').onsubmit=async e=>{e.preventDefault();const d=new FormData(e.currentTarget),m=$('#tail-message');try{const x=await request('/api/connections/cloudflare-tail',{method:'POST',headers:{'content-type':'application/json'},body:JSON.stringify({name:d.get('name'),signingSecret:d.get('signingSecret')||undefined,generateSecret:d.get('generateSecret')==='on'})});if(x.generatedSecret){$('#tail-generated-value').textContent=x.generatedSecret;$('#tail-generated').classList.remove('hidden')}e.currentTarget.reset();m.textContent='Tail installation saved. Its secret remains write-only.';await load()}catch(x){m.textContent=x.message}};$('#copy-tail-secret').onclick=async()=>{await navigator.clipboard.writeText($('#tail-generated-value').textContent);$('#copy-tail-secret').textContent='Copied'};bindActions();load();`);
+$('#tail-connection').onsubmit=async e=>{e.preventDefault();const form=e.currentTarget,d=new FormData(form),m=$('#tail-message'),id=form.dataset.id,url='/api/connections/cloudflare-tail'+(id?'/'+encodeURIComponent(id):'');try{const x=await request(url,{method:id?'PUT':'POST',headers:{'content-type':'application/json'},body:JSON.stringify({name:d.get('name'),signingSecret:d.get('signingSecret')||undefined,generateSecret:d.get('generateSecret')==='on'})});if(x.generatedSecret){$('#tail-generated-value').textContent=x.generatedSecret;$('#tail-generated').classList.remove('hidden')}form.reset();delete form.dataset.id;m.textContent='Tail installation saved. Its secret remains write-only.';await load()}catch(x){m.textContent=x.message}};$('#copy-tail-secret').onclick=async()=>{await navigator.clipboard.writeText($('#tail-generated-value').textContent);$('#copy-tail-secret').textContent='Copied'};bindActions();load();`);
export const apiKeysSettingsPage = (viewer: { email: string }) => shell("API Keys — Factorize", viewer, settingsLayout("api-keys", `${dashboardHead("API Keys", "Manage API keys for programmatic access to Factorize.")}
diff --git a/packages/app/test/ui.test.ts b/packages/app/test/ui.test.ts
index 94d9858d..23040d62 100644
--- a/packages/app/test/ui.test.ts
+++ b/packages/app/test/ui.test.ts
@@ -130,6 +130,13 @@ describe("pages", () => {
expect(settings).toContain('id="installed-loading"');
expect(settings).toContain('id="installed-empty"');
expect(settings).toContain('data-open-setup="exe"');
+ expect(settings).toContain('aria-haspopup="dialog"');
+ expect(settings).toContain('