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
2 changes: 1 addition & 1 deletion packages/app/public/styles.css

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions packages/app/src/tailwind.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@
}
@custom-variant dark (&:where(.dark, .dark *));

@layer utilities {
/* Keep the job controls compact while allowing their row to wrap on phones. */
#job-detail > div.mt-6 > div:last-child > :is(button, a) {
min-height: 2.5rem;
padding: .5rem .75rem;
border-radius: .5rem;
}
}

@theme {
/* Bee palette: soft honey surfaces paired with warm charcoal neutrals. */
--color-factorize-50: #fff9e6;
Expand Down
8 changes: 4 additions & 4 deletions packages/app/src/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const triggerBadge=t=>{const labels={manual:'Manual only',schedule:'Scheduled',w
const jobStatus=j=>j.runningCount>0?{label:'Running',classes:'bg-blue-500 ring-blue-200 dark:ring-blue-900'}:{label:'Idle',classes:'bg-stone-300 ring-stone-200 dark:bg-slate-600 dark:ring-slate-800'};
`;

export const jobsPage = (viewer: { email: string }) => shell("Jobs — Factorize", viewer, `<main class="mx-auto w-full max-w-6xl px-4 py-8 sm:px-5 sm:py-12 lg:px-8">
export const jobsPage = (viewer: { email: string }) => shell("Jobs — Factorize", viewer, `<main class="mx-auto w-full max-w-6xl min-w-0 px-4 py-8 sm:px-5 sm:py-12 lg:px-8">
${dashboardHead("Jobs", "", '<a href="/jobs/new" class="inline-flex w-full justify-center rounded-xl bg-slate-950 px-4 py-2.5 text-sm font-semibold text-white dark:bg-white dark:text-slate-950 sm:w-auto sm:px-5 sm:py-3">Create job</a>')}
<section id="jobs" class="${card} mt-6 overflow-hidden sm:mt-8"><p class="p-6 text-sm text-slate-500 sm:p-8">Loading jobs…</p></section></main>`, `${uiHelpers}
async function load(){const jobs=await request('/api/v1/jobs');const root=$('#jobs');if(!jobs.length){root.innerHTML='<div class="p-8 text-center sm:p-10"><h2 class="font-semibold">No jobs yet</h2><p class="mt-2 text-sm text-slate-500">Create a manual-only or automatically triggered job.</p></div>';return}root.innerHTML='<ul class="divide-y divide-stone-200 dark:divide-slate-800">'+jobs.map(j=>{const status=jobStatus(j);return '<li class="flex min-w-0 items-center gap-3 px-4 py-4 sm:gap-4 sm:p-6"><span class="h-3 w-3 shrink-0 rounded-full ring-2 '+status.classes+'" role="img" aria-label="'+status.label+'" title="'+status.label+'"></span><div class="min-w-0"><div class="flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1"><a class="break-words font-semibold hover:text-factorize-700" href="/jobs/'+encodeURIComponent(j.id)+'">'+esc(j.name)+'</a>'+(j.enabled?'':'<span class="text-xs font-semibold text-slate-500">Disabled</span>')+'</div><p class="mt-1 text-xs text-slate-500 sm:mt-2 sm:text-sm"><span class="font-medium text-slate-700 dark:text-slate-300">'+esc(j.runningCount)+'/'+esc(j.concurrencyLimit)+' Running</span></p></div></li>'}).join('')+'</ul>'}load().catch(e=>$('#jobs').innerHTML='<p class="p-6 text-red-700">'+esc(e.message)+'</p>');`);
Expand Down Expand Up @@ -153,7 +153,7 @@ form.executionTargetId.addEventListener('change',()=>syncModels('',''));
window.addEventListener('focus',()=>refreshAvailability().catch(()=>{}));window.addEventListener('pageshow',()=>refreshAvailability().catch(()=>{}));
form.onsubmit=async e=>{e.preventDefault();const error=$('#error');error.classList.add('hidden');try{if(!triggers.length)throw new Error('Add at least one trigger.');const body={name:form.name.value,slug:form.slug.value,promptTemplate:form.promptTemplate.value,model:form.model.value.trim(),effort:form.effort.value.trim(),concurrencyLimit:Number(form.concurrencyLimit.value),executionTargetId:form.executionTargetId.value,triggers:triggers.map(({id,slug,kind,enabled,config})=>({id,slug,kind,enabled,config}))};const result=await request('/api/v1/jobs'+(jobId?'/'+encodeURIComponent(jobId):''),{method:jobId?'PUT':'POST',headers:{'content-type':'application/json'},body:JSON.stringify(body)});location.href='/jobs/'+encodeURIComponent(result.id)}catch(e){error.textContent=e.message;error.classList.remove('hidden');error.scrollIntoView({block:'center'})}};init().catch(e=>{const error=$('#error');error.textContent=e.message;error.classList.remove('hidden')});`);

export const jobDetailPage = (viewer: { email: string }, jobId: string) => shell("Job — Factorize", viewer, `<main class="mx-auto w-full max-w-6xl min-w-0 px-5 py-12 lg:px-8"><div id="job-detail" class="min-w-0" data-id="${escapeHtml(jobId)}"><p class="text-sm text-slate-500">Loading job…</p></div>
export const jobDetailPage = (viewer: { email: string }, jobId: string) => shell("Job — Factorize", viewer, `<main class="mx-auto w-full max-w-6xl min-w-0 px-4 py-8 sm:px-5 sm:py-12 lg:px-8"><div id="job-detail" class="min-w-0" data-id="${escapeHtml(jobId)}"><p class="text-sm text-slate-500">Loading job…</p></div>
<dialog id="manual-run-dialog" aria-labelledby="manual-run-title" class="m-auto w-[min(34rem,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"><form id="manual-run-form"><div class="p-6"><h2 id="manual-run-title" class="text-lg font-semibold">Run job manually</h2><p class="mt-2 text-sm text-slate-500 dark:text-slate-400">Add an optional prompt for this run.</p><label class="label mt-6" for="manual-run-prompt">Prompt</label><textarea id="manual-run-prompt" name="prompt" class="field min-h-32 resize-y" placeholder="Leave blank to skip prompt"></textarea><p id="manual-run-error" class="mt-3 hidden rounded-lg bg-red-50 p-3 text-sm text-red-700 dark:bg-red-950/40 dark:text-red-300" role="alert"></p><div class="mt-6 flex justify-end gap-3"><button id="cancel-manual-run" type="button" class="min-h-11 px-4 text-sm font-semibold">Cancel</button><button id="submit-manual-run" type="submit" class="min-h-11 rounded-xl bg-slate-950 px-4 text-sm font-semibold text-white disabled:cursor-wait disabled:opacity-60 dark:bg-white dark:text-slate-950">Run now</button></div></div></form></dialog></main>`, `${uiHelpers}
const id=$('#job-detail').dataset.id,root=$('#job-detail');
const manualRunDialog=$('#manual-run-dialog'),manualRunForm=$('#manual-run-form');
Expand All @@ -166,7 +166,7 @@ function elapsedSince(value){const seconds=Math.max(0,Math.floor((Date.now()-new
function refreshRunElapsed(){document.querySelectorAll('[data-run-started]').forEach(label=>label.textContent=elapsedSince(label.dataset.runStarted))}
async function load(){clearInterval(elapsedTimer);const [j,runs]=await Promise.all([request('/api/v1/jobs/'+encodeURIComponent(id)),request('/api/v1/runs?jobId='+encodeURIComponent(id))]),triggers=j.triggers||[],status=jobStatus(j),hasActiveRuns=runs.items.some(r=>activeRunStates.includes(r.state));jobRunsState.page=1;jobRunsState.cursors=[null];jobRunsState.runs=runs;root.innerHTML='<nav aria-label="Breadcrumb"><ol class="flex flex-wrap items-center gap-2 text-sm text-slate-500"><li><a href="/jobs" class="font-medium hover:text-slate-950 dark:hover:text-white">Jobs</a></li><li aria-hidden="true">/</li><li aria-current="page" class="truncate font-medium text-slate-950 dark:text-white">'+esc(j.name)+'</li></ol></nav><div class="mt-6 grid min-w-0 items-start gap-5 sm:grid-cols-[minmax(0,1fr)_auto]"><div class="min-w-0"><h1 class="w-full break-words text-3xl font-bold tracking-tight">'+esc(j.name)+'</h1><div class="mt-3 flex items-center gap-3"><span class="h-3.5 w-3.5 shrink-0 rounded-full ring-4 '+status.classes+'" role="img" aria-label="'+status.label+'" title="'+status.label+'"></span><span class="text-sm font-medium text-slate-700 dark:text-slate-300">'+esc(j.runningCount)+'/'+esc(j.concurrencyLimit)+' Running</span>'+(j.enabled?'':'<span class="text-sm text-slate-500">Disabled</span>')+'</div><details class="mt-3"><summary class="w-fit cursor-pointer text-sm font-semibold text-factorize-700 dark:text-factorize-100">Details</summary><div class="mt-3 space-y-4 text-sm text-slate-600 dark:text-slate-300"><dl class="grid gap-2 sm:grid-cols-[8rem_minmax(0,1fr)]"><dt class="font-semibold text-slate-950 dark:text-white">Triggers</dt><dd>'+(triggers.length?triggers.map(t=>triggerBadge(t.kind)).join(' '):'None')+'</dd><dt class="font-semibold text-slate-950 dark:text-white">Model</dt><dd>'+esc(j.model||'Harness default')+'</dd></dl><div><h2 class="font-semibold text-slate-950 dark:text-white">Prompt template</h2><pre class="mt-2 overflow-x-auto whitespace-pre-wrap rounded-xl bg-slate-950 p-4 text-sm text-slate-100">'+esc(j.promptTemplate)+'</pre></div></div></details></div><div class="flex flex-wrap items-start gap-2 sm:justify-end"><button id="run" class="rounded-xl bg-factorize-500 px-4 py-2.5 text-sm font-semibold text-slate-950">Run now</button><button id="toggle" class="rounded-xl border border-stone-300 px-4 py-2.5 text-sm font-semibold">'+(j.enabled?'Disable':'Enable')+'</button><a href="/jobs/'+encodeURIComponent(id)+'/edit" class="rounded-xl border border-stone-300 px-4 py-2.5 text-sm font-semibold">Edit</a><button id="delete" class="rounded-xl border border-red-200 px-4 py-2.5 text-sm font-semibold text-red-700">Delete</button></div></div><section data-job-runs-section class="${card} mt-8 min-w-0 overflow-hidden"><div class="border-b border-stone-200 p-6 dark:border-slate-800"><h2 class="font-semibold">Runs</h2></div>'+(runs.items.length?jobRunsMarkup(runs):'<p data-job-runs-list class="p-8 text-sm text-slate-500">No runs yet.</p>')+'</section>';refreshJobRunsPagination();if(hasActiveRuns)elapsedTimer=setInterval(refreshRunElapsed,1000);$('#run').onclick=openManualRun;$('#toggle').onclick=async()=>{await request('/api/v1/jobs/'+encodeURIComponent(id)+'/'+(j.enabled?'disable':'enable'),{method:'POST'});load()};$('#delete').onclick=async()=>{if(confirm('Delete this job and its queued history?')){await request('/api/v1/jobs/'+encodeURIComponent(id),{method:'DELETE'});location.href='/jobs'}}}load().catch(e=>root.innerHTML='<p class="text-red-700">'+esc(e.message)+'</p>');`);

export const jobRunPage = (viewer: { email: string }, runId: string) => shell("Run — Factorize", viewer, `<main class="mx-auto w-full max-w-6xl min-w-0 px-5 py-12 lg:px-8"><div id="run-detail" class="min-w-0" data-id="${escapeHtml(runId)}"><p class="text-sm text-slate-500">Loading run…</p></div></main>`, `${uiHelpers}
export const jobRunPage = (viewer: { email: string }, runId: string) => shell("Run — Factorize", viewer, `<main class="mx-auto w-full max-w-6xl min-w-0 px-4 py-8 sm:px-5 sm:py-12 lg:px-8"><div id="run-detail" class="min-w-0" data-id="${escapeHtml(runId)}"><p class="text-sm text-slate-500">Loading run…</p></div></main>`, `${uiHelpers}
const root=$('#run-detail'),id=root.dataset.id,activeStates=['queued','starting','running','recovering','blocked','stopping'];let refreshTimer,elapsedTimer;
function outputText(r){return r.live_output??r.result??'Output is not available yet.'}
function elapsed(r){const start=new Date(r.created_at).getTime(),end=activeStates.includes(r.state)?Date.now():new Date(r.updated_at||r.created_at).getTime(),seconds=Math.max(0,Math.floor((end-start)/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'}
Expand All @@ -175,7 +175,7 @@ function scheduleRefresh(r){clearTimeout(refreshTimer);if(activeStates.includes(
async function refreshOutput(){try{const r=await request('/api/v1/runs/'+encodeURIComponent(id)),output=$('[data-run-output]'),state=$('[data-run-state]');if(output){const follow=output.scrollHeight-output.scrollTop-output.clientHeight<24;output.innerHTML=ansiToHtml(outputText(r));if(follow)output.scrollTop=output.scrollHeight}if(state)state.innerHTML=stateBadge(r.state);updateElapsed(r);scheduleRefresh(r)}catch{refreshTimer=setTimeout(refreshOutput,5000)}}
request('/api/v1/runs/'+encodeURIComponent(id)).then(async r=>({r,j:await request('/api/v1/jobs/'+encodeURIComponent(r.job_id))})).then(({r,j})=>{const caps=r.capabilities||[],canOutput=caps.includes('output'),canStop=caps.includes('stop')&&['starting','running','blocked'].includes(r.state),runLabel='Run '+r.id.slice(0,8);root.innerHTML='<nav aria-label="Breadcrumb"><ol class="flex min-w-0 flex-wrap items-center gap-2 text-sm text-slate-500"><li><a href="/jobs" class="font-medium hover:text-slate-950 dark:hover:text-white">Jobs</a></li><li aria-hidden="true">/</li><li class="min-w-0 max-w-full"><a href="/jobs/'+encodeURIComponent(r.job_id)+'" class="block truncate font-medium hover:text-slate-950 dark:hover:text-white">'+esc(j.name)+'</a></li><li aria-hidden="true">/</li><li aria-current="page" class="min-w-0 max-w-full truncate font-medium text-slate-950 dark:text-white">'+esc(runLabel)+'</li></ol></nav><div class="mt-6 flex min-w-0 flex-wrap items-start justify-between gap-4"><div class="min-w-0"><h1 class="break-words text-3xl font-bold">'+esc(runLabel)+'</h1><p data-run-elapsed class="mt-2 text-slate-500">'+elapsed(r)+'</p></div><div class="flex min-w-0 flex-wrap items-center gap-3"><span data-run-state>'+stateBadge(r.state)+'</span>'+(canStop?'<button id="stop-run" class="rounded-xl border border-red-200 px-4 py-2 text-sm font-semibold text-red-700">Stop run</button>':'')+'</div></div><details data-run-prompt-details class="${card} mt-8 min-w-0 overflow-hidden p-6"><summary class="cursor-pointer font-semibold">Prompt</summary><pre data-run-prompt class="mt-4 min-w-0 max-w-full overflow-x-auto whitespace-pre-wrap break-words rounded-xl bg-slate-950 p-4 font-mono text-xs leading-5 text-slate-100">'+esc(r.prompt||'Prompt is not available for this run.')+'</pre></details>'+(canOutput?'<section class="${card} mt-6 min-w-0 overflow-hidden p-6"><div class="flex min-w-0 items-center justify-between gap-4"><h2 class="font-semibold">Output</h2>'+(activeStates.includes(r.state)?'<span class="shrink-0 text-xs text-slate-500" aria-live="polite">Live · refreshes automatically</span>':'')+'</div><pre data-run-output class="mt-4 min-w-0 max-w-full max-h-[calc(100vh-12rem)] overflow-auto whitespace-pre-wrap rounded-xl bg-slate-950 p-4 font-mono text-xs leading-5 text-slate-100" aria-live="polite">'+ansiToHtml(outputText(r))+'</pre></section>':'<section class="${card} mt-6 min-w-0 p-6 text-sm text-slate-500">Output is not available for this run.</section>');const output=$('[data-run-output]');if(output)output.scrollTop=output.scrollHeight;if(canStop)$('#stop-run').onclick=async()=>{await request('/api/v1/runs/'+encodeURIComponent(id)+'/stop',{method:'POST'});location.reload()};updateElapsed(r);scheduleRefresh(r)}).catch(e=>root.innerHTML='<p class="text-red-700">'+esc(e.message)+'</p>');`);

const settingsLayout = (active: "integrations" | "api-keys", content: string) => `<main class="mx-auto w-full max-w-6xl px-5 py-12 lg:px-8"><div class="grid gap-8 md:grid-cols-[13rem_minmax(0,1fr)] md:gap-10"><nav aria-label="Settings" class="flex gap-2 overflow-x-auto border-b border-stone-200 pb-3 md:block md:border-b-0 md:pb-0 dark:border-slate-800">
const settingsLayout = (active: "integrations" | "api-keys", content: string) => `<main class="mx-auto w-full max-w-6xl min-w-0 px-4 py-8 sm:px-5 sm:py-12 lg:px-8"><div class="grid min-w-0 gap-8 md:grid-cols-[13rem_minmax(0,1fr)] md:gap-10"><nav aria-label="Settings" class="flex gap-2 overflow-x-auto border-b border-stone-200 pb-3 md:block md:border-b-0 md:pb-0 dark:border-slate-800">
${[["integrations", "Integrations"], ["api-keys", "API Keys"]].map(([id, label]) => `<a href="/settings/${id}"${active === id ? ` aria-current="page"` : ""} class="flex min-h-11 shrink-0 items-center rounded-lg px-3 py-2 text-sm text-slate-600 hover:bg-stone-100 hover:text-slate-950 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-factorize-600 aria-[current=page]:bg-stone-100 aria-[current=page]:font-semibold aria-[current=page]:text-slate-950 md:mb-1 dark:text-slate-300 dark:hover:bg-slate-800 dark:hover:text-white dark:aria-[current=page]:bg-slate-800 dark:aria-[current=page]:text-white">${label}</a>`).join("")}
</nav><div class="min-w-0">${content}</div></div></main>`;

Expand Down
8 changes: 4 additions & 4 deletions packages/app/test/ui.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe("pages", () => {

it("keeps paginated run content width stable", () => {
const html = jobDetailPage({ email: "owner@example.com" }, "job-1");
expect(html).toContain('<main class="mx-auto w-full max-w-6xl min-w-0');
expect(html).toContain('<main class="mx-auto w-full max-w-6xl min-w-0 px-4 py-8 sm:px-5 sm:py-12 lg:px-8">');
expect(html).toContain('id="job-detail" class="min-w-0"');
expect(html).toContain('data-job-runs-section');
expect(html).toContain('class="min-w-0 divide-y');
Expand Down Expand Up @@ -162,7 +162,7 @@ describe("pages", () => {

it("keeps the Jobs page proportionate and overflow-safe on phones", () => {
const html = jobsPage({ email: "owner@example.com" });
expect(html).toContain('<main class="mx-auto w-full max-w-6xl px-4 py-8 sm:px-5 sm:py-12 lg:px-8">');
expect(html).toContain('<main class="mx-auto w-full max-w-6xl min-w-0 px-4 py-8 sm:px-5 sm:py-12 lg:px-8">');
expect(html).toContain('class="flex flex-col items-stretch gap-3 sm:flex-row sm:items-end sm:justify-between sm:gap-4"');
expect(html).toContain('class="inline-flex w-full justify-center rounded-xl');
expect(html).toContain('sm:w-auto sm:px-5 sm:py-3">Create job</a>');
Expand Down Expand Up @@ -230,7 +230,7 @@ describe("pages", () => {

it("aligns Settings with the Jobs page width and gutters", () => {
const settings = settingsPage({ email: "owner@example.com" });
expect(settings).toContain('<main class="mx-auto w-full max-w-6xl px-5 py-12 lg:px-8">');
expect(settings).toContain('<main class="mx-auto w-full max-w-6xl min-w-0 px-4 py-8 sm:px-5 sm:py-12 lg:px-8">');
expect(settings).not.toContain('<main class="mx-auto max-w-4xl');
});

Expand Down Expand Up @@ -362,7 +362,7 @@ describe("pages", () => {
expect(detail).not.toContain("const triggerDetail=");
expect(detail).not.toContain("esc(t.slug)+' · '+esc(t.kind)");
expect(detail.indexOf('>Details</summary>')).toBeLessThan(detail.indexOf('Prompt template'));
expect(run).toContain('class="mx-auto w-full max-w-6xl min-w-0');
expect(run).toContain('class="mx-auto w-full max-w-6xl min-w-0 px-4 py-8 sm:px-5 sm:py-12 lg:px-8');
expect(run).toContain('id="run-detail" class="min-w-0"');
expect(run).toContain('<nav aria-label="Breadcrumb">');
expect(run).toContain("request('/api/v1/jobs/'+encodeURIComponent(r.job_id))");
Expand Down