From 88c34e58e6607d967a46f943c4ee6ab193b6e12a Mon Sep 17 00:00:00 2001 From: Brendan Asselstine Date: Fri, 9 Oct 2026 18:37:25 +0000 Subject: [PATCH] fix: preserve mutation feedback and reconcile authoritative state (GEN-2156) --- docs/gen-2156-validation.md | 30 ++++ packages/app/src/page-refresh.ts | 7 +- packages/app/src/ui.ts | 84 ++++++---- packages/app/test/api-keys.browser.test.ts | 40 +++++ .../app/test/page-refresh.browser.test.ts | 146 +++++++++++++++++- .../test/settings-mutations.browser.test.ts | 52 +++++++ packages/app/test/ui.test.ts | 2 +- 7 files changed, 323 insertions(+), 38 deletions(-) create mode 100644 docs/gen-2156-validation.md create mode 100644 packages/app/test/settings-mutations.browser.test.ts diff --git a/docs/gen-2156-validation.md b/docs/gen-2156-validation.md new file mode 100644 index 00000000..71afa37b --- /dev/null +++ b/docs/gen-2156-validation.md @@ -0,0 +1,30 @@ +# GEN-2156 validation + +Mutation state lives outside replaceable controls. Job/run/settings reads capture a generation and discard results if a mutation has started or completed since the read began. Requested refreshes are queued while a poll is busy and resume after visibility/focus restoration. Confirmed mutation responses acknowledge enable and stop immediately; background read errors are separate from mutation errors. + +Both Run paths retain the logical submission's idempotency key on retries, close the prompt dialog immediately, retain its draft, and display an explicitly unaccepted pending request. A new input creates a new logical submission. Navigation waits for the canonical run ID. Keys persist for the lifetime of the page, including polling rerenders; a full page reload does not retain an unresolved submission. + +Kill remains the existing stop request API. Availability is restricted to starting/running/blocked. Queued, stopping, and terminal states have no Kill control. History remains visible; stopping does not claim immediate termination. + +Scheduler wake remains awaited for REST and MCP. This change makes no claim of server latency improvement and introduces no asynchronous notification or recovery mechanism. + +## Controlled timing comparison + +Measured on 2026-10-09 by executing the generated job detail browser scripts from main (4afa350) and this implementation in happy-dom with Vitest fake timers. The enable POST fixture takes 200 ms before a simulated awaited wake of 400 ms; GET fixtures take 200 ms. The benchmark sampled the rendered button each millisecond. These are injected timings, not production measurements or measurements of a real Durable Object. + +| Metric | Main | Implementation | +| --- | ---: | ---: | +| Simulated mutation request duration | 600 ms | 600 ms | +| Simulated awaited wake duration | 400 ms | 400 ms | +| Click to visible enable feedback | 800 ms | 0 ms | +| Click to confirmed enable state | 800 ms | 600 ms | + +The retained browser regression asserts immediate Starting feedback with a delayed 600 ms invocation response and navigation only after confirmation. Request and wake durations remain unchanged by design. Production request/wake timing should be measured independently before changing scheduler delivery. + +## Automated validation + +`npm run check --workspace=factorize` runs generated OpenAPI verification, API boundary checks, auth-email script tests, TypeScript, Vitest, and a Wrangler deployment dry run. + +Browser coverage executes generated scripts with delayed responses, changing polling snapshots, older reads resolving after mutation completion, uncertain outcomes, retries, prompt recovery, all stop-availability states, artifact-cleaning deletion, token creation/revocation, client disconnection, integration removal, and connection testing. Existing REST/MCP manual invocation replay tests exercise server idempotency. + +PostgreSQL integration suites require their configured test database and are skipped when it is absent. No production credentials, connections, jobs, or database contents are modified by validation. diff --git a/packages/app/src/page-refresh.ts b/packages/app/src/page-refresh.ts index 7f0e7c0e..c4ac37a4 100644 --- a/packages/app/src/page-refresh.ts +++ b/packages/app/src/page-refresh.ts @@ -1,16 +1,17 @@ /** Shared browser orchestration. Completion-based timers prevent overlapping polls. */ export const pageRefreshBrowserSource = ` function pageRefresh(load,{delay=()=>3000,onError=()=>{}}={}){ - let timer,busy=false,stopped=false,failures=0; + let timer,busy=false,stopped=false,failures=0,queued=false; const clear=()=>{clearTimeout(timer);timer=undefined}; const schedule=ms=>{clear();if(!stopped&&!document.hidden&&ms!==null)timer=setTimeout(refresh,ms)}; async function refresh(){ - if(stopped||document.hidden||busy)return; + if(stopped||document.hidden||busy){queued=true;return} + queued=false; clear();busy=true; let next; try{await load();failures=0;next=delay()} catch(error){failures++;next=Math.min(30000,5000*2**(failures-1));onError(error)} - finally{busy=false;schedule(next)} + finally{busy=false;if(queued&&!stopped&&!document.hidden){queued=false;refresh()}else schedule(next)} } const resume=()=>{clear();if(!document.hidden)refresh()}; const hide=()=>{stopped=true;clear()}; diff --git a/packages/app/src/ui.ts b/packages/app/src/ui.ts index 6578e62f..4a4eee3c 100644 --- a/packages/app/src/ui.ts +++ b/packages/app/src/ui.ts @@ -94,7 +94,21 @@ const uiHelpers = ` const $=s=>document.querySelector(s),esc=v=>String(v??'').replace(/[&<>"']/g,c=>({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c])); ${ansiToHtmlBrowserSource} ${pageRefreshBrowserSource} -const request=async(url,options)=>{const requestUrl=String(url).startsWith('/api/v1/runs?jobId=')&&!String(url).includes('limit=')?String(url)+'&limit=20':url,r=await fetch(requestUrl,options),body=await r.json().catch(()=>({}));if(r.status===401){location.href='/auth/login';throw new Error('Unauthorized')}if(!r.ok)throw new Error(body.error?.message||body.error||'Request failed');return body}; +const request=async(url,options)=>{const requestUrl=String(url).startsWith('/api/v1/runs?jobId=')&&!String(url).includes('limit=')?String(url)+'&limit=20':url,r=await fetch(requestUrl,options),body=await r.json().catch(()=>({}));if(r.status===401){location.href='/auth/login';throw new Error('Unauthorized')}if(!r.ok){const error=new Error(body.error?.message||body.error||'Request failed');error.definitive=r.status>=400&&r.status<500;throw error;}return body}; +// State belongs to the page, not replaceable controls. Each mutation invalidates older reads. +let mutationGeneration=0; +const pendingMutations=new Map(); +function applyPendingMutations(){ + document.querySelectorAll('[data-mutation-label]').forEach(button=>{if(![...pendingMutations.keys()].some(selector=>button.matches(selector))){button.disabled=false;button.textContent=button.dataset.mutationLabel;delete button.dataset.mutationLabel}}); + for(const [selector,label] of pendingMutations){document.querySelectorAll(selector).forEach(button=>{if(button.dataset.mutationLabel===undefined)button.dataset.mutationLabel=button.textContent;button.disabled=true;if(button.textContent!==label)button.textContent=label})} +} + +async function mutate(selector,label,operation){ + if(pendingMutations.has(selector))return; + pendingMutations.set(selector,label);mutationGeneration++;applyPendingMutations(); + try{return await operation()}finally{mutationGeneration++;pendingMutations.delete(selector);applyPendingMutations();if(typeof applyEnabled==='function')applyEnabled()} +} +const reconcile=(refresh)=>{Promise.resolve().then(refresh).catch(()=>{})}; const jobRunsPageSize=20,jobRunsState={page:1,cursors:[null],runs:null,loading:false}; const jobRunsMarkup=r=>r.items?.length?'':'

No runs yet.

'; const jobRunsControls=(r,page)=>{if(page===1&&!r.nextCursor)return'';const previous=page>1?'':' disabled aria-disabled="true"',next=r.nextCursor?'':' disabled aria-disabled="true"';return''}; @@ -192,23 +206,30 @@ export const jobDetailPage = (viewer: { email: string }, jobId: string) => shell

Run job manually

Add an optional prompt for this run.

`, `${uiHelpers} const id=$('#job-detail').dataset.id,root=$('#job-detail'); const manualRunDialog=$('#manual-run-dialog'),manualRunForm=$('#manual-run-form'); - const nativeJobFetch=window.fetch.bind(window);window.fetch=async(input,init)=>{const response=await nativeJobFetch(input,init);if(!init?.method&&String(input).includes('/api/v1/jobs/'))response.clone().json().then(j=>setTimeout(()=>{const details=root.querySelector('dl');if(details&&!details.querySelector('[data-name-template]'))details.insertAdjacentHTML('beforeend','
Name template
'+esc(j.runNameTemplate||'Default run name')+'
')},0)).catch(()=>{});return response}; -function openManualRun(){closeRunMenu();manualRunForm.reset();$('#manual-run-error').classList.add('hidden');manualRunDialog.showModal();$('#manual-run-prompt').focus()} +function openManualRun(){closeRunMenu();$('#manual-run-error').classList.toggle('hidden',!runError);manualRunDialog.showModal();$('#manual-run-prompt').focus()} $('#cancel-manual-run').onclick=()=>manualRunDialog.close();manualRunDialog.onclick=e=>{if(e.target===manualRunDialog)manualRunDialog.close()}; -async function createManualRun(input){const x=await request('/api/v1/jobs/'+encodeURIComponent(id)+'/invocations',{method:'POST',headers:{'content-type':'application/json'},body:JSON.stringify(input)});location.href='/job-runs/'+encodeURIComponent(x.runId)} -let manualRunPending=false; -function setRunPending(value){manualRunPending=value;['run','run-options','run-with-prompt','submit-manual-run'].forEach(id=>{const button=$('#'+id);if(button)button.disabled=value})} +let manualRunPending=false,manualSubmission=null,runError=''; +function setRunPending(value){manualRunPending=value;['run','run-options','run-with-prompt','submit-manual-run'].forEach(id=>{const button=$('#'+id);if(button){button.disabled=value;if(id==='run')button.textContent=value?'Starting…':'Run'}});const error=$('#run-error');if(error){error.textContent=runError;error.hidden=!runError}let indicator=$('[data-pending-run]');if(value&&!indicator){root.querySelector('[data-job-runs-section]')?.insertAdjacentHTML('afterbegin','

Starting… Awaiting acceptance of your run request.

')}if(!value)indicator?.remove()} +async function submitManualRun(input){ + if(manualRunPending)return; + if(!manualSubmission||JSON.stringify(manualSubmission.input)!==JSON.stringify(input))manualSubmission={input,idempotencyKey:crypto.randomUUID()}; + runError='';closeRunMenu();setRunPending(true);manualRunDialog.close();mutationGeneration++; + try{const x=await request('/api/v1/jobs/'+encodeURIComponent(id)+'/invocations',{method:'POST',headers:{'content-type':'application/json'},body:JSON.stringify({...input,idempotencyKey:manualSubmission.idempotencyKey})});manualSubmission=null;location.href='/job-runs/'+encodeURIComponent(x.runId)} + catch(e){runError=e.message+(e.definitive?'':' Outcome unknown. Retry uses the same submission key.');setRunPending(false);const error=$('#manual-run-error');error.textContent=runError;error.classList.remove('hidden');reconcile(()=>jobRefresh.refresh())} + finally{mutationGeneration++} +} function closeRunMenu(restoreFocus=false){const menu=$('#run-menu'),button=$('#run-options');if(!menu)return;menu.hidden=true;button.setAttribute('aria-expanded','false');if(restoreFocus)button.focus()} document.addEventListener('click',e=>{if(!e.target.closest('[data-run-actions]'))closeRunMenu()}); document.addEventListener('focusin',e=>{if(!e.target.closest('[data-run-actions]'))closeRunMenu()}); document.addEventListener('keydown',e=>{if(e.key==='Escape'&&$('#run-menu')&&!$('#run-menu').hidden){e.preventDefault();closeRunMenu(true)}}); -async function runImmediately(){if(manualRunPending)return;closeRunMenu();const error=$('#run-error');error.hidden=true;setRunPending(true);try{await createManualRun({})}catch(e){error.textContent=e.message;error.hidden=false;setRunPending(false)}} -manualRunForm.onsubmit=async e=>{e.preventDefault();if(manualRunPending)return;const error=$('#manual-run-error');setRunPending(true);error.classList.add('hidden');try{await createManualRun({prompt:manualRunForm.elements.prompt.value})}catch(e){error.textContent=e.message;error.classList.remove('hidden');setRunPending(false)}}; +async function runImmediately(){return submitManualRun({})} +manualRunForm.onsubmit=e=>{e.preventDefault();return submitManualRun({prompt:manualRunForm.elements.prompt.value})}; const activeRunStates=['queued','starting','running','blocked','stopping'];let elapsedTimer; function elapsedSince(value){const seconds=Math.max(0,Math.floor((Date.now()-new Date(value).getTime())/1000)),hours=Math.floor(seconds/3600),minutes=Math.floor(seconds%3600/60),remainder=seconds%60;return(hours?hours+'h ':'')+(minutes||hours?minutes+'m ':'')+remainder+'s elapsed'} function refreshRunElapsed(){document.querySelectorAll('[data-run-started]').forEach(label=>label.textContent=elapsedSince(label.dataset.runStarted))} -let jobSnapshot,jobActive=false; -async function load(){if(jobRunsState.loading)return;jobRunsState.loading=true;try{const cursor=jobRunsState.cursors[jobRunsState.page];const [j,runs]=await Promise.all([request('/api/v1/jobs/'+encodeURIComponent(id)),request('/api/v1/runs?jobId='+encodeURIComponent(id)+'&limit='+jobRunsPageSize+(cursor?'&cursor='+encodeURIComponent(cursor):''))]),triggers=j.triggers||[],status=jobStatus(j),hasActiveRuns=runs.items.some(r=>activeRunStates.includes(r.state));jobActive=j.runningCount>0||hasActiveRuns;const snapshot=JSON.stringify([j,runs,jobRunsState.page]);if(snapshot===jobSnapshot)return;jobSnapshot=snapshot;clearInterval(elapsedTimer);jobRunsState.runs=runs;replacePageContent(root,'

'+esc(j.name)+'

'+esc(j.runningCount)+'/'+esc(j.concurrencyLimit)+' Running'+(j.enabled?'':'Disabled')+'
Details
Triggers
'+(triggers.length?triggers.map(t=>triggerBadge(t.kind)).join(' '):'None')+'
Model
'+esc(j.model||'Harness default')+'

Prompt template

'+esc(j.promptTemplate)+'
Edit

Runs

'+(runs.items.length?jobRunsMarkup(runs):'

No runs yet.

')+'
',refreshJobRunsPagination);if(hasActiveRuns)elapsedTimer=setInterval(refreshRunElapsed,1000);setRunPending(manualRunPending);$('#run').onclick=runImmediately;$('#run-with-prompt').onclick=openManualRun;$('#run-options').onclick=()=>{const menu=$('#run-menu');menu.hidden=!menu.hidden;$('#run-options').setAttribute('aria-expanded',String(!menu.hidden));if(!menu.hidden)$('#run-with-prompt').focus()};$('#run-options').onkeydown=e=>{if(e.key==='ArrowDown'){e.preventDefault();$('#run-menu').hidden=false;$('#run-options').setAttribute('aria-expanded','true');$('#run-with-prompt').focus()}};$('#toggle').onclick=async()=>{await request('/api/v1/jobs/'+encodeURIComponent(id)+'/'+(j.enabled?'disable':'enable'),{method:'POST'});jobRefresh.refresh()};$('#delete').onclick=async()=>{if(confirm('Delete this job and its queued history?')){await request('/api/v1/jobs/'+encodeURIComponent(id),{method:'DELETE'});location.href='/jobs'}}}finally{jobRunsState.loading=false}} +let jobSnapshot,jobActive=false,enabledOverride; +function applyEnabled(){const button=$('#toggle');if(button&&enabledOverride!==undefined){button.textContent=pendingMutations.has('#toggle')?(enabledOverride?'Enabling…':'Disabling…'):(enabledOverride?'Disable':'Enable');const badge=$('[data-enabled-badge]');if(badge)badge.textContent=enabledOverride?'Enabled':'Disabled'}} +async function load(){if(jobRunsState.loading)return;jobRunsState.loading=true;try{const generation=mutationGeneration;const cursor=jobRunsState.cursors[jobRunsState.page];const [j,runs]=await Promise.all([request('/api/v1/jobs/'+encodeURIComponent(id)),request('/api/v1/runs?jobId='+encodeURIComponent(id)+'&limit='+jobRunsPageSize+(cursor?'&cursor='+encodeURIComponent(cursor):''))]);if(generation!==mutationGeneration){reconcile(()=>jobRefresh.refresh());return}if(enabledOverride!==undefined){if(!pendingMutations.has('#toggle'))enabledOverride=undefined;else j.enabled=enabledOverride}const triggers=j.triggers||[],status=jobStatus(j),hasActiveRuns=runs.items.some(r=>activeRunStates.includes(r.state));jobActive=j.runningCount>0||hasActiveRuns;const snapshot=JSON.stringify([j,runs,jobRunsState.page]);if(snapshot===jobSnapshot)return;jobSnapshot=snapshot;clearInterval(elapsedTimer);jobRunsState.runs=runs;replacePageContent(root,'

'+esc(j.name)+'

'+esc(j.runningCount)+'/'+esc(j.concurrencyLimit)+' Running'+''+(j.enabled?'Enabled':'Disabled')+''+'
Details
Triggers
'+(triggers.length?triggers.map(t=>triggerBadge(t.kind)).join(' '):'None')+'
Model
'+esc(j.model||'Harness default')+'
Name template
'+esc(j.runNameTemplate||'Default run name')+'

Prompt template

'+esc(j.promptTemplate)+'
Edit

Runs

'+(runs.items.length?jobRunsMarkup(runs):'

No runs yet.

')+'
',refreshJobRunsPagination);if(hasActiveRuns)elapsedTimer=setInterval(refreshRunElapsed,1000);setRunPending(manualRunPending);$('#run').onclick=runImmediately;$('#run-with-prompt').onclick=openManualRun;$('#run-options').onclick=()=>{const menu=$('#run-menu');menu.hidden=!menu.hidden;$('#run-options').setAttribute('aria-expanded',String(!menu.hidden));if(!menu.hidden)$('#run-with-prompt').focus()};$('#run-options').onkeydown=e=>{if(e.key==='ArrowDown'){e.preventDefault();$('#run-menu').hidden=false;$('#run-options').setAttribute('aria-expanded','true');$('#run-with-prompt').focus()}};applyEnabled();applyPendingMutations();$('#toggle').onclick=()=>mutate('#toggle',j.enabled?'Disabling…':'Enabling…',async()=>{const prior=j.enabled;enabledOverride=!prior;applyEnabled();try{const result=await request('/api/v1/jobs/'+encodeURIComponent(id)+'/'+(prior?'disable':'enable'),{method:'POST'});enabledOverride=result.enabled;j.enabled=result.enabled}catch(e){if(e.definitive)enabledOverride=prior;runError=e.message+(e.definitive?'':' Outcome unknown; checking server state.');setRunPending(manualRunPending)}finally{applyEnabled();reconcile(()=>jobRefresh.refresh())}});$('#delete').onclick=()=>{if(confirm('Delete this job and its queued history?'))mutate('#delete','Deleting…',async()=>{try{await request('/api/v1/jobs/'+encodeURIComponent(id),{method:'DELETE'});location.href='/jobs'}catch(e){runError=e.message;setRunPending(manualRunPending);reconcile(()=>jobRefresh.refresh())}})}}finally{jobRunsState.loading=false}} const jobRefresh=pageRefresh(load,{delay:()=>jobActive?3000:10000,onError:e=>{if(!jobSnapshot)root.innerHTML='

'+esc(e.message)+'

'}});`); export const jobRunPage = (viewer: { email: string }, runId: string) => shell("Run — Factorize", viewer, `

Loading run…

`, `${uiHelpers} @@ -232,13 +253,13 @@ function updateRun(r){ root.classList.toggle('trace-running',r.state==='running'); const activity=$('[data-trace-activity]');if(activity)activity.hidden=r.state!=='running'; const state=$('[data-run-state]');if(state)state.innerHTML=stateBadge(r.state); - if(!activeStates.includes(r.state))$('#kill-run')?.remove(); + if(!['starting','running','blocked'].includes(r.state))$('#kill-run')?.remove(); const live=$('[data-run-live]');if(live)live.hidden=!activeStates.includes(r.state); const artifact=$('[data-run-artifact]');if(artifact)artifact.textContent=traceSourceLabel(r)+(r.artifact_error?' · '+r.artifact_error:''); updateElapsed(r); } -async function refreshOutput(){const r=await request('/api/v1/runs/'+encodeURIComponent(id));const reset=currentRun&&(r.trace_generation!==currentRun.trace_generation||JSON.stringify(r.trace_projection)!==JSON.stringify(currentRun.trace_projection)||(activeStates.includes(currentRun.state)&&!activeStates.includes(r.state)));updateRun(r);if(traceLoading)await traceLoading;traceDone=false;await loadTrace(Boolean(reset))} -async function loadRun(){return request('/api/v1/runs/'+encodeURIComponent(id)).then(async r=>({r,j:await request('/api/v1/jobs/'+encodeURIComponent(r.job_id))})).then(async({r,j})=>{const canKill=activeStates.includes(r.state),runLabel=r.name||r.run_name||r.issue_title||'Run '+r.id.slice(0,8);document.title=runLabel+' — Factorize';root.innerHTML='

'+esc(runLabel)+'

'+elapsed(r)+'

'+queueTime(r)+'

'+stateBadge(r.state)+''+(canKill?'':'')+'
'+triggerProvenance(r)+'
Prompt
'+esc(r.prompt||'Prompt is not available for this run.')+'

Trace

'+esc(traceSourceLabel(r))+'

'+(activeStates.includes(r.state)?'Live · refreshes automatically':'')+'

Trace events are not available yet.

';if(canKill)$('#kill-run').onclick=async()=>{if(!confirm('Kill this run and release its concurrency slot?'))return;await request('/api/v1/runs/'+encodeURIComponent(id)+'/kill',{method:'POST'});await runRefresh.refresh()};$('[data-trace-more]').onclick=()=>{traceDone=false;loadTrace().catch(()=>{})};updateRun(r);await loadTrace()})} +async function refreshOutput(){const generation=mutationGeneration;const r=await request('/api/v1/runs/'+encodeURIComponent(id));if(generation!==mutationGeneration){reconcile(()=>runRefresh.refresh());return}const reset=currentRun&&(r.trace_generation!==currentRun.trace_generation||JSON.stringify(r.trace_projection)!==JSON.stringify(currentRun.trace_projection)||(activeStates.includes(currentRun.state)&&!activeStates.includes(r.state)));updateRun(r);if(traceLoading)await traceLoading;traceDone=false;await loadTrace(Boolean(reset))} +async function loadRun(){return request('/api/v1/runs/'+encodeURIComponent(id)).then(async r=>({r,j:await request('/api/v1/jobs/'+encodeURIComponent(r.job_id))})).then(async({r,j})=>{const canKill=['starting','running','blocked'].includes(r.state),runLabel=r.name||r.run_name||r.issue_title||'Run '+r.id.slice(0,8);document.title=runLabel+' — Factorize';root.innerHTML='

'+esc(runLabel)+'

'+elapsed(r)+'

'+queueTime(r)+'

'+stateBadge(r.state)+''+(canKill?'':'')+'
'+triggerProvenance(r)+'
Prompt
'+esc(r.prompt||'Prompt is not available for this run.')+'

Trace

'+esc(traceSourceLabel(r))+'

'+(activeStates.includes(r.state)?'Live · refreshes automatically':'')+'

Trace events are not available yet.

';if(canKill)$('#kill-run').onclick=()=>{if(!confirm('Request this run to stop? It remains visible until the backend confirms termination.'))return;mutate('#kill-run','Stopping…',async()=>{try{const result=await request('/api/v1/runs/'+encodeURIComponent(id)+'/kill',{method:'POST'});updateRun({...currentRun,state:result.state})}catch(e){let error=$('[data-stop-error]');if(!error){root.insertAdjacentHTML('afterbegin','

');error=$('[data-stop-error]')}error.textContent=e.message+(e.definitive?'':' Outcome unknown; checking server state.')}reconcile(()=>runRefresh.refresh())})};$('[data-trace-more]').onclick=()=>{traceDone=false;loadTrace().catch(()=>{})};updateRun(r);await loadTrace()})} const runRefresh=pageRefresh(async()=>{if(!currentRun)await loadRun();else await refreshOutput()},{delay:()=>activeStates.includes(currentRun.state)?3000:['pending','collecting'].includes(currentRun.artifact_state)?10000:null,onError:e=>{if(!currentRun)root.innerHTML='

'+esc(e.message)+'

'}});`); const settingsLayout = (active: "integrations" | "api-keys", content: string) => `