diff --git a/src/tenant.ts b/src/tenant.ts index ff0dac5f..18f10de6 100644 --- a/src/tenant.ts +++ b/src/tenant.ts @@ -296,7 +296,7 @@ export class Tenant extends DurableObject { const offset = (page - 1) * 10; const events = view === "events" ? this.rows("SELECT id, delivery_id, issue_id, issue_url, event_type, event_action, outcome, detail, provider, received_at FROM flow_events WHERE flow_id = ? ORDER BY received_at DESC, id DESC LIMIT 11 OFFSET ?", flowId, offset) : []; const runs = view === "runs" ? this.rows("SELECT id, issue_id, issue_title, issue_url, claim_key, agent_name, workspace_name, agent_kind, state, provider, prompt, result, created_at, updated_at, exec_request, exec_response, exec_status, exec_exit_code, recovery_reason, recovery_attempt, recovery_last_action, recovery_started_at FROM runs WHERE pipe_id = ? AND state != 'ignored' ORDER BY created_at DESC, id DESC LIMIT 11 OFFSET ?", flowId, offset) : []; - await this.backfillRunTitles(runs); + await this.backfillRunIssueDetails(runs); const hasNext = (view === "events" ? events : runs).length > 10; if (events.length > 10) events.pop(); if (runs.length > 10) runs.pop(); @@ -311,18 +311,21 @@ export class Tenant extends DurableObject { return json({ flow, events, runs, pagination: { page, hasNext } }); } - private async backfillRunTitles(runs: Row[]): Promise { - const missing = runs.filter((run) => String(run.provider || "linear") === "linear" && !String(run.issue_title || "").trim()); - if (!missing.length) return; + private async backfillRunIssueDetails(runs: Row[]): Promise { + const uuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i; + const incomplete = runs.filter((run) => String(run.provider || "linear") === "linear" && (!String(run.issue_title || "").trim() || uuid.test(String(run.issue_id)))); + if (!incomplete.length) return; const linear = await this.connection<{ accessToken: string }>("linear"); if (!linear) return; - await Promise.all(missing.map(async (run) => { + await Promise.all(incomplete.map(async (run) => { try { const data = await this.linear(linear.accessToken, LINEAR_ISSUE_PROJECT_QUERY, { id: String(run.issue_id) }); - const title = text(object(data?.issue).title).trim(); - if (!title) return; - run.issue_title = title; - this.ctx.storage.sql.exec("UPDATE runs SET issue_title = ? WHERE id = ?", title, run.id); + const issue = object(data?.issue); + const title = text(issue.title).trim(); + const identifier = text(issue.identifier).trim(); + if (title) run.issue_title = title; + if (identifier) run.issue_id = identifier; + if (title || identifier) this.ctx.storage.sql.exec("UPDATE runs SET issue_title = ?, issue_id = ? WHERE id = ?", run.issue_title, run.issue_id, run.id); } catch { // A stale or inaccessible issue should not prevent the runs page loading. } @@ -332,6 +335,7 @@ export class Tenant extends DurableObject { private async runDetail(runId: string): Promise { const run = this.one("SELECT runs.*, pipes.name AS flow_name FROM runs JOIN pipes ON pipes.id = runs.pipe_id WHERE runs.id = ?", runId); if (!run) return new Response("Not found", { status: 404 }); + await this.backfillRunIssueDetails([run]); for (const field of ["prompt", "exec_request", "exec_response", "result"] as const) { if (run.state !== "ignored" && typeof run[field] === "string" && run[field]) run[field] = await decrypt(String(run[field]), this.env.CREDENTIAL_ENCRYPTION_KEY); } diff --git a/src/ui.ts b/src/ui.ts index d5da042b..13575f05 100644 --- a/src/ui.ts +++ b/src/ui.ts @@ -153,9 +153,8 @@ export const flowDetailPage = (viewer: { email: string }, flowId: string) => she
← My Flows

Loading agent runs…

`, ` const root=document.querySelector('#flow-detail'),flowId=root.dataset.flowId,esc=v=>{const d=document.createElement('div');d.textContent=v??'';return d.innerHTML},time=v=>new Date(v).toLocaleString(),badge=value=>''+esc(value)+''; const issueLink=(id,url)=>{if(!id)return '—';const trusted=typeof url==='string'&&(url.startsWith('https://linear.app/')||/^https:\\/\\/github\\.com\\/[A-Za-z0-9_.-]+\\/[A-Za-z0-9_.-]+\\/pull\\/\\d+$/.test(url)),href=trusted?url:'https://linear.app/issue/'+encodeURIComponent(id);return ''+esc(id)+' ↗'}; -const detail=(title,value)=>value?'

'+title+'

'+esc(value)+'
':''; const pager=p=>p.page===1&&!p.hasNext?'':''; -async function load(){const page=Math.max(1,parseInt(new URLSearchParams(location.search).get('page')||'1',10)||1),response=await fetch('/api/pipes/'+encodeURIComponent(flowId)+'?view=runs&page='+page);if(response.status===401)return location.href='/auth/linear';if(!response.ok){root.innerHTML='

Could not load this flow.

';return}const data=await response.json(),flow=data.flow,pagination=data.pagination||{page:1,hasNext:false},panels=(data.runs||[]).map(run=>'
'+esc(run.issue_id)+(run.issue_title?': '+esc(run.issue_title):'')+''+esc(run.agent_kind||flow.agent_kind||'Herdr agent')+' · '+esc(run.agent_name)+''+badge(run.state)+''+time(run.updated_at)+'
'+detail('Prompt sent to agent',run.prompt)+detail('Exact command submitted to exe.dev',run.exec_request)+detail('Actual exe.dev response',run.exec_response)+detail('Full agent output',run.result)+'
').join('')||'

No agent runs yet.

';root.innerHTML='

'+esc(flow.name)+'

'+esc(flow.filter_type)+' trigger · '+esc(flow.max_concurrency)+' concurrent agents · '+esc(flow.agent_kind||'Herdr agent')+' · workspace '+esc(flow.workspace_name||'—')+'

Webhook activityEdit Flow

Agent runs

Open a run page or expand a row to inspect its output.

'+panels+pager(pagination)+'
'}load(); +async function load(){const page=Math.max(1,parseInt(new URLSearchParams(location.search).get('page')||'1',10)||1),response=await fetch('/api/pipes/'+encodeURIComponent(flowId)+'?view=runs&page='+page);if(response.status===401)return location.href='/auth/linear';if(!response.ok){root.innerHTML='

Could not load this flow.

';return}const data=await response.json(),flow=data.flow,pagination=data.pagination||{page:1,hasNext:false},rows=(data.runs||[]).map(run=>''+esc(run.issue_id)+(run.issue_title?': '+esc(run.issue_title):'')+''+esc(run.agent_kind||flow.agent_kind||'Herdr agent')+' · '+esc(run.agent_name)+''+badge(run.state)+''+time(run.updated_at)+'').join('')||'

No agent runs yet.

';root.innerHTML='

'+esc(flow.name)+'

'+esc(flow.filter_type)+' trigger · '+esc(flow.max_concurrency)+' concurrent agents · '+esc(flow.agent_kind||'Herdr agent')+' · workspace '+esc(flow.workspace_name||'—')+'

Webhook activityEdit Flow

Agent runs

Select a run to inspect its details and full output.

'+rows+pager(pagination)+'
'}load(); `); export const flowWebhooksPage = (viewer: { email: string }, flowId: string) => shell("Webhook activity — Factorize", viewer, ` diff --git a/test/ui.test.ts b/test/ui.test.ts index ab0589b4..8023f269 100644 --- a/test/ui.test.ts +++ b/test/ui.test.ts @@ -65,11 +65,10 @@ describe("pages", () => { expect(html).toContain("/runs/"); expect(html).toContain("Edit Flow"); expect(html).toContain("issueLink"); - expect(html).toContain("Prompt sent to agent"); - expect(html).toContain("Full agent output"); expect(html).toContain("issue_title"); expect(html).toContain("esc(run.issue_id)+(run.issue_title?': '+esc(run.issue_title):'')"); - expect(html).toContain('max-h-[32rem] overflow-auto'); + expect(html).toContain("Select a run to inspect its details and full output."); + expect(html).not.toContain('