diff --git a/packages/app/src/ui.ts b/packages/app/src/ui.ts index 3f50783e..8fcc6010 100644 --- a/packages/app/src/ui.ts +++ b/packages/app/src/ui.ts @@ -135,7 +135,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(),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, `
← Jobs

Loading job…

+export const jobDetailPage = (viewer: { email: string }, jobId: string) => shell("Job — Factorize", viewer, `

Loading job…

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'); @@ -143,14 +143,14 @@ function openManualRun(){manualRunForm.reset();$('#manual-run-error').classList. $('#cancel-manual-run').onclick=()=>manualRunDialog.close();manualRunDialog.onclick=e=>{if(e.target===manualRunDialog)manualRunDialog.close()}; manualRunForm.onsubmit=async e=>{e.preventDefault();const button=$('#submit-manual-run'),error=$('#manual-run-error');button.disabled=true;error.classList.add('hidden');try{const x=await request('/api/v1/jobs/'+encodeURIComponent(id)+'/invocations',{method:'POST',headers:{'content-type':'application/json'},body:JSON.stringify({prompt:manualRunForm.elements.prompt.value})});location.href='/job-runs/'+encodeURIComponent(x.runId)}catch(e){error.textContent=e.message;error.classList.remove('hidden');button.disabled=false}}; manualRunForm.onsubmit=async e=>{e.preventDefault();const button=$('#submit-manual-run'),error=$('#manual-run-error');button.disabled=true;error.classList.add('hidden');try{const x=await request('/api/v1/jobs/'+encodeURIComponent(id)+'/invocations',{method:'POST',headers:{'content-type':'application/json'},body:JSON.stringify({prompt:manualRunForm.elements.prompt.value})});location.href='/job-runs/'+encodeURIComponent(x.runId)}catch(e){error.textContent=e.message;error.classList.remove('hidden');button.disabled=false}}; -async function load(){const [j,runs]=await Promise.all([request('/api/v1/jobs/'+encodeURIComponent(id)),request('/api/v1/runs?jobId='+encodeURIComponent(id))]),triggers=j.triggers||[];const triggerDetail=triggers.map(t=>esc(t.slug)+' · '+esc(t.kind)).join(' · ');root.innerHTML='

'+esc(j.name)+'

'+triggers.map(t=>triggerBadge(t.kind)).join('')+(j.enabled?'':'Disabled')+'

'+triggerDetail+' · '+j.concurrencyLimit+' concurrent · '+esc(j.model||'Harness default')+'

Edit

Prompt template

'+esc(j.promptTemplate)+'

Runs

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

No runs yet.

')+'
';$('#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='

'+esc(e.message)+'

');`); +async function load(){const [j,runs]=await Promise.all([request('/api/v1/jobs/'+encodeURIComponent(id)),request('/api/v1/runs?jobId='+encodeURIComponent(id))]),triggers=j.triggers||[];const triggerDetail=triggers.map(t=>esc(t.slug)+' · '+esc(t.kind)).join(' · ');root.innerHTML='

'+esc(j.name)+'

'+triggers.map(t=>triggerBadge(t.kind)).join('')+(j.enabled?'':'Disabled')+'

'+triggerDetail+' · '+j.concurrencyLimit+' concurrent · '+esc(j.model||'Harness default')+'

Edit

Prompt template

'+esc(j.promptTemplate)+'

Runs

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

No runs yet.

')+'
';$('#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='

'+esc(e.message)+'

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

Loading run…

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

Loading run…

`, `${uiHelpers} const root=$('#run-detail'),id=root.dataset.id,activeStates=['starting','running','blocked','stopping'];let refreshTimer; function outputText(r){return r.live_output??r.result??'Output is not available yet.'} function scheduleRefresh(r){clearTimeout(refreshTimer);if(activeStates.includes(r.state)&&(r.capabilities||[]).includes('output'))refreshTimer=setTimeout(refreshOutput,3000)} async function refreshOutput(){try{const r=await request('/api/v1/runs/'+encodeURIComponent(id)),output=$('[data-run-output]'),state=$('[data-run-state]');if(output)output.innerHTML=ansiToHtml(outputText(r));if(state)state.innerHTML=stateBadge(r.state);scheduleRefresh(r)}catch{refreshTimer=setTimeout(refreshOutput,5000)}} -request('/api/v1/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?'

Context is not available for this legacy run.

':'
'+esc(JSON.stringify(r.context,null,2))+'
';root.innerHTML='← Job

Run '+esc(r.id.slice(0,8))+'

'+esc(r.backend_kind)+' · '+new Date(r.created_at).toLocaleString()+'

'+stateBadge(r.state)+''+(canStop?'':'')+'

Observation

'+(trusted?'Open '+esc(r.backend_kind)+' destination ↗':'

This backend has no external observation link.

')+'

Context sent to agent

'+context+'
'+(canOutput?'

Output

'+(activeStates.includes(r.state)?'Live · refreshes automatically':'')+'
'+ansiToHtml(outputText(r))+'
':'
Output is available only in the backend observation experience.
');if(canStop)$('#stop-run').onclick=async()=>{await request('/api/v1/runs/'+encodeURIComponent(id)+'/stop',{method:'POST'});location.reload()};scheduleRefresh(r)}).catch(e=>root.innerHTML='

'+esc(e.message)+'

');`); +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),trusted=typeof r.destination_url==='string'&&r.destination_url.startsWith('https://'),context=r.context===null?'

Context is not available for this legacy run.

':'
'+esc(JSON.stringify(r.context,null,2))+'
',runLabel='Run '+r.id.slice(0,8);root.innerHTML='

'+esc(runLabel)+'

'+esc(r.backend_kind)+' · '+new Date(r.created_at).toLocaleString()+'

'+stateBadge(r.state)+''+(canStop?'':'')+'

Observation

'+(trusted?'Open '+esc(r.backend_kind)+' destination ↗':'

This backend has no external observation link.

')+'

Context sent to agent

'+context+'
'+(canOutput?'

Output

'+(activeStates.includes(r.state)?'Live · refreshes automatically':'')+'
'+ansiToHtml(outputText(r))+'
':'
Output is available only in the backend observation experience.
');if(canStop)$('#stop-run').onclick=async()=>{await request('/api/v1/runs/'+encodeURIComponent(id)+'/stop',{method:'POST'});location.reload()};scheduleRefresh(r)}).catch(e=>root.innerHTML='

'+esc(e.message)+'

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