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/src/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ async function runNow(job){const value=prompt('Prompt for this manual run:','');
async function load(){const [j,runs]=await Promise.all([request('/api/jobs/'+encodeURIComponent(id)),request('/api/job-runs?jobId='+encodeURIComponent(id))]),triggers=j.triggers||[];const triggerDetail=triggers.map(t=>esc(t.slug)+' · '+esc(t.kind)).join(' · ');root.innerHTML='<div class="flex flex-wrap items-start justify-between gap-4"><div><div class="flex items-center gap-3"><h1 class="text-3xl font-bold tracking-tight">'+esc(j.name)+'</h1>'+triggers.map(t=>triggerBadge(t.kind)).join('')+(j.enabled?'':'<span class="text-sm text-slate-500">Disabled</span>')+'</div><p class="mt-2 text-slate-500">'+triggerDetail+' · '+j.concurrencyLimit+' concurrent</p></div><div class="flex flex-wrap gap-2"><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 class="${card} mt-8 p-6"><h2 class="font-semibold">Prompt template</h2><pre class="mt-4 overflow-x-auto whitespace-pre-wrap rounded-xl bg-slate-950 p-4 text-sm text-slate-100">'+esc(j.promptTemplate)+'</pre></section><section class="${card} mt-6 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?'<ul class="divide-y divide-stone-200 dark:divide-slate-800">'+runs.items.map(r=>'<li><a class="flex items-center justify-between gap-4 p-5 hover:bg-stone-50 dark:hover:bg-slate-800" href="/job-runs/'+encodeURIComponent(r.id)+'"><span><span class="font-medium">'+esc(r.provider||r.agent_kind||'Factorize')+'</span><span class="mt-1 block text-xs text-slate-500">'+new Date(r.created_at).toLocaleString()+'</span></span>'+stateBadge(r.state)+'</a></li>').join('')+'</ul>':'<p class="p-8 text-sm text-slate-500">No runs yet.</p>')+'</section>';$('#run').onclick=()=>runNow(j).catch(alert);$('#toggle').onclick=async()=>{await request('/api/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/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 max-w-5xl px-5 py-12 lg:px-8"><div id="run-detail" 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;request('/api/job-runs/'+encodeURIComponent(id)).then(r=>{const caps=r.capabilities||[],canOutput=caps.includes('output'),canStop=caps.includes('stop')&&['starting','running','blocked'].includes(r.state),trusted=typeof r.destination_url==='string'&&r.destination_url.startsWith('https://');root.innerHTML='<a href="/jobs/'+encodeURIComponent(r.job_id)+'" class="text-sm font-medium text-slate-500">← Job</a><div class="mt-6 flex flex-wrap items-start justify-between gap-4"><div><h1 class="text-3xl font-bold">Run '+esc(r.id.slice(0,8))+'</h1><p class="mt-2 text-slate-500">'+esc(r.backend_kind)+' · '+new Date(r.created_at).toLocaleString()+'</p></div><div class="flex items-center gap-3">'+stateBadge(r.state)+(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><section class="${card} mt-8 p-6"><h2 class="font-semibold">Observation</h2>'+(trusted?'<a class="mt-3 inline-flex font-semibold text-factorize-700 underline" target="_blank" rel="noreferrer" href="'+esc(r.destination_url)+'">Open '+esc(r.backend_kind)+' destination ↗</a>':'<p class="mt-3 text-sm text-slate-500">This backend has no external observation link.</p>')+'</section>'+(canOutput?'<section class="${card} mt-6 p-6"><h2 class="font-semibold">Output</h2><pre data-run-output class="mt-4 overflow-x-auto whitespace-pre-wrap rounded-xl bg-slate-950 p-4 font-mono text-xs leading-5 text-slate-100">'+ansiToHtml(r.result||'Output is not available yet.')+'</pre></section>':'<section class="${card} mt-6 p-6 text-sm text-slate-500">Output is available only in the backend observation experience.</section>');if(canStop)$('#stop-run').onclick=async()=>{await request('/api/job-runs/'+encodeURIComponent(id)+'/stop',{method:'POST'});location.reload()}}).catch(e=>root.innerHTML='<p class="text-red-700">'+esc(e.message)+'</p>');`);
const root=$('#run-detail'),id=root.dataset.id;request('/api/job-runs/'+encodeURIComponent(id)).then(r=>{const caps=r.capabilities||[],canOutput=caps.includes('output'),canStop=caps.includes('stop')&&['starting','running','blocked'].includes(r.state),trusted=typeof r.destination_url==='string'&&r.destination_url.startsWith('https://'),context=r.context===null?'<p class="mt-3 text-sm text-slate-500">Context is not available for this legacy run.</p>':'<pre data-run-context class="mt-4 overflow-x-auto whitespace-pre-wrap rounded-xl bg-slate-950 p-4 font-mono text-xs leading-5 text-slate-100">'+esc(JSON.stringify(r.context,null,2))+'</pre>';root.innerHTML='<a href="/jobs/'+encodeURIComponent(r.job_id)+'" class="text-sm font-medium text-slate-500">← Job</a><div class="mt-6 flex flex-wrap items-start justify-between gap-4"><div><h1 class="text-3xl font-bold">Run '+esc(r.id.slice(0,8))+'</h1><p class="mt-2 text-slate-500">'+esc(r.backend_kind)+' · '+new Date(r.created_at).toLocaleString()+'</p></div><div class="flex items-center gap-3">'+stateBadge(r.state)+(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><section class="${card} mt-8 p-6"><h2 class="font-semibold">Observation</h2>'+(trusted?'<a class="mt-3 inline-flex font-semibold text-factorize-700 underline" target="_blank" rel="noreferrer" href="'+esc(r.destination_url)+'">Open '+esc(r.backend_kind)+' destination ↗</a>':'<p class="mt-3 text-sm text-slate-500">This backend has no external observation link.</p>')+'</section><section class="${card} mt-6 p-6"><h2 class="font-semibold">Context sent to agent</h2>'+context+'</section>'+(canOutput?'<section class="${card} mt-6 p-6"><h2 class="font-semibold">Output</h2><pre data-run-output class="mt-4 overflow-x-auto whitespace-pre-wrap rounded-xl bg-slate-950 p-4 font-mono text-xs leading-5 text-slate-100">'+ansiToHtml(r.result||'Output is not available yet.')+'</pre></section>':'<section class="${card} mt-6 p-6 text-sm text-slate-500">Output is available only in the backend observation experience.</section>');if(canStop)$('#stop-run').onclick=async()=>{await request('/api/job-runs/'+encodeURIComponent(id)+'/stop',{method:'POST'});location.reload()}}).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 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">
${[["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("")}
Expand Down
4 changes: 4 additions & 0 deletions packages/app/test/ui.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,10 @@ describe("pages", () => {
expect(run).toContain("destination_url");
expect(run).toContain("caps.includes('output')");
expect(run).toContain('data-run-output');
expect(run).toContain("Context sent to agent");
expect(run).toContain('data-run-context');
expect(run).toContain("JSON.stringify(r.context,null,2)");
expect(run).toContain("Context is not available for this legacy run.");
expect(run).toContain('font-mono text-xs leading-5');
expect(run).toContain("ansiToHtml(r.result");
expect(run).not.toContain("__name");
Expand Down