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.

8 changes: 3 additions & 5 deletions packages/app/src/tailwind.css
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,8 @@
.dark .trace-token-number, .dark .trace-token-variable { color: #7dd3fc; }
.trace-thinking { display: flex; align-items: center; gap: .5rem; color: var(--trace-muted); font-size: .8rem; padding: .25rem 0; }
.trace-spinner { width: .8rem; height: .8rem; border: 2px solid var(--trace-border); border-top-color: var(--trace-accent); border-radius: 50%; }
.trace-thinking-live { display: none; }
.trace-running .trace-at-end > .trace-thinking:last-child .trace-spinner { animation: trace-spin 1s linear infinite; }
.trace-running .trace-at-end > .trace-thinking:last-child .trace-thinking-live { display: inline; }
.trace-running .trace-at-end > .trace-thinking:last-child .trace-thinking-past { display: none; }
.trace-activity[hidden] { display: none; }
.trace-activity:not([hidden]) .trace-spinner { animation: trace-spin 1s linear infinite; }
@keyframes trace-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .trace-running .trace-at-end > .trace-thinking:last-child .trace-spinner { animation: none; } }
@media (prefers-reduced-motion: reduce) { .trace-activity:not([hidden]) .trace-spinner { animation: none; } }
}
2 changes: 1 addition & 1 deletion packages/app/src/trace-presentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const traceContent=input=>{
};
const traceCard=e=>{
const type=e.type,title=traceEscape(e.title),preview=String(e.preview||'').slice(0,32768);
if(type==='reasoning')return '<div class="trace-thinking"><span class="trace-spinner" aria-hidden="true"></span><span class="trace-thinking-live">Thinking…</span><span class="trace-thinking-past">Thought</span></div>';
if(type==='reasoning')return '<div class="trace-thinking"><span class="trace-spinner" aria-hidden="true"></span><span>Thought</span></div>';
if(type==='user_message'||type==='assistant_message')return '<article class="trace-message trace-'+type+'"><h3>'+ (type==='user_message'?'You':'Assistant')+'</h3><div class="trace-prose">'+traceContent(preview)+'</div></article>';
const tool=['tool_call','tool_result','command','file_change'].includes(type);
let content=traceCode(preview);
Expand Down
3 changes: 2 additions & 1 deletion packages/app/src/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,14 +230,15 @@ function traceSourceLabel(r){const source=r.trace_projection?.source_kind||r.tra
function updateRun(r){
currentRun=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();
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='<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><p data-run-queue class="mt-1 text-sm text-slate-500">'+queueTime(r)+'</p></div><div class="flex min-w-0 flex-wrap items-center gap-3"><span data-run-state>'+stateBadge(r.state)+'</span>'+(canKill?'<button id="kill-run" class="rounded-xl border border-red-200 px-4 py-2 text-sm font-semibold text-red-700">Kill run</button>':'')+'</div></div>'+triggerProvenance(r)+'<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><section class="${card} mt-6 min-w-0 overflow-hidden p-6"><div class="flex flex-wrap items-center justify-between gap-3"><div><h2 class="font-semibold">Trace</h2><p data-run-artifact class="mt-1 text-xs text-slate-500">'+esc(traceSourceLabel(r))+'</p></div>'+(activeStates.includes(r.state)?'<span data-run-live class="text-xs text-slate-500" aria-live="polite">Live · refreshes automatically</span>':'')+'</div><p data-trace-empty class="mt-6 text-sm text-slate-500">Trace events are not available yet.</p><div data-run-trace class="trace-list mt-5"></div><button data-trace-more class="mt-5 hidden rounded-xl border border-stone-300 px-4 py-2 text-sm font-semibold">Load more</button></section>';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 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='<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><p data-run-queue class="mt-1 text-sm text-slate-500">'+queueTime(r)+'</p></div><div class="flex min-w-0 flex-wrap items-center gap-3"><span data-run-state>'+stateBadge(r.state)+'</span>'+(canKill?'<button id="kill-run" class="rounded-xl border border-red-200 px-4 py-2 text-sm font-semibold text-red-700">Kill run</button>':'')+'</div></div>'+triggerProvenance(r)+'<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><section class="${card} mt-6 min-w-0 overflow-hidden p-6"><div class="flex flex-wrap items-center justify-between gap-3"><div><h2 class="font-semibold">Trace</h2><p data-run-artifact class="mt-1 text-xs text-slate-500">'+esc(traceSourceLabel(r))+'</p></div>'+(activeStates.includes(r.state)?'<span data-run-live class="text-xs text-slate-500" aria-live="polite">Live · refreshes automatically</span>':'')+'</div><p data-trace-empty class="mt-6 text-sm text-slate-500">Trace events are not available yet.</p><div data-run-trace class="trace-list mt-5"></div><div data-trace-activity hidden class="trace-list trace-thinking trace-activity mt-5" role="status"><span class="trace-spinner" aria-hidden="true"></span><span>Thinking…</span></div><button data-trace-more class="mt-5 hidden rounded-xl border border-stone-300 px-4 py-2 text-sm font-semibold">Load more</button></section>';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()})}
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='<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 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">
Expand Down
58 changes: 58 additions & 0 deletions packages/app/test/page-refresh.browser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,3 +305,61 @@ describe("lifecycle page refresh", () => {
});

});

describe("persistent trace activity", () => {
it.each(['succeeded', 'failed', 'canceled'])("stays at the trace end between events and disappears on %s", async terminal => {
let current = { ...run, state: 'running', artifact_state: 'stored' };
let items = [event(1)];
let resolveTrace: ((response: Response) => void) | undefined;
let pause = false;
render(jobRunPage(viewer, run.id), vi.fn(async (input: string) => {
if (input.includes('/trace?')) {
if (pause) return new Promise<Response>(resolve => { resolveTrace = resolve; });
const after = Number(new URL(input, 'https://app').searchParams.get('after'));
return json({ items: items.filter(item => item.sequence > after), nextCursor: null });
}
return json(input.startsWith('/api/v1/jobs/') ? job : current);
}));
await flush();
const trace = document.querySelector('[data-run-trace]');
const activity = document.querySelector('[data-trace-activity]');
expect(activity.hidden).toBe(false);
expect(trace.nextElementSibling).toBe(activity);
expect(activity.textContent).toBe('Thinking…');
await vi.advanceTimersByTimeAsync(3000);
expect(trace.children).toHaveLength(1);
expect(activity.hidden).toBe(false);
pause = true;
await vi.advanceTimersByTimeAsync(3000);
expect(activity.hidden).toBe(false);
items.push(event(2));
resolveTrace!(json({ items: [event(2)], nextCursor: null }));
await flush();
expect(trace.children).toHaveLength(2);
expect(trace.nextElementSibling).toBe(activity);
expect(activity.hidden).toBe(false);
pause = false;
current = { ...current, state: terminal };
await vi.advanceTimersByTimeAsync(3000);
expect(activity.hidden).toBe(true);
});

it.each(['queued', 'starting', 'blocked', 'stopping', 'succeeded', 'failed', 'canceled'])("does not show activity when opening a %s run", async state => {
render(jobRunPage(viewer, run.id), vi.fn(async (input: string) => {
if (input.includes('/trace?')) return json({ items: [event(1)], nextCursor: null });
return json(input.startsWith('/api/v1/jobs/') ? job : { ...run, state });
}));
await flush();
expect(document.querySelector('[data-trace-activity]').hidden).toBe(true);
});

it("shows activity for a running run with no trace events yet", async () => {
render(jobRunPage(viewer, run.id), vi.fn(async (input: string) => {
if (input.includes('/trace?')) return json({ items: [], nextCursor: null });
return json(input.startsWith('/api/v1/jobs/') ? job : { ...run, state: 'running' });
}));
await flush();
expect(document.querySelector('[data-run-trace]').children).toHaveLength(0);
expect(document.querySelector('[data-trace-activity]').hidden).toBe(false);
});
});
4 changes: 2 additions & 2 deletions packages/app/test/trace-presentation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('trace presentation', () => {
});
it('replaces reasoning bodies with a compact indicator and leaves errors visible', () => {
const node = dom(traceCard({type:'reasoning',title:'Reasoning',preview:'private reasoning'}));
expect(node.textContent).toContain('Thinking…');
expect(node.textContent).toBe('Thought');
expect(node.textContent).not.toContain('private reasoning');
expect(node.textContent).not.toContain('Reasoning');
expect(dom(traceCard({type:'error',title:'Failed',preview:'error'})).querySelector('details')?.open).toBe(true);
Expand All @@ -51,7 +51,7 @@ describe('trace presentation', () => {
expect(dom(traceContent('<task>\n'.repeat(4000))).querySelectorAll('details')).toHaveLength(1);
expect(dom(traceCard({type:'tool_result',title:'Output',preview:'x'.repeat(40000)})).querySelector('code')?.textContent).toHaveLength(32768);
});
it('keeps cursor-based append rendering and gates animation on the latest page and running state', () => {
it('keeps cursor-based append rendering and keeps activity separate from trace pagination and reasoning events', () => {
const html = jobRunPage({email:'test@example.com'},'run');
expect(html).toContain("list.insertAdjacentHTML('beforeend',page.items.map(traceCard).join(''))");
expect(html).toContain("list.classList.toggle('trace-at-end',!page.nextCursor)");
Expand Down
Loading