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 public/styles.css

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion src/tenant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,10 @@ export class Tenant extends DurableObject<Env> {
async fetch(request: Request): Promise<Response> {
const url = new URL(request.url);
try {
if (request.method === "GET" && url.pathname === "/pipes") return json(this.rows("SELECT id, name, project_id, team_id, filter_type, filter_target_id, source_kind, source_config, trigger_kind, trigger_config, max_concurrency, workspace_name, agent_kind, enabled, created_at FROM pipes ORDER BY created_at DESC"));
if (request.method === "GET" && url.pathname === "/pipes") return json(this.rows(`SELECT id, name, project_id, team_id, filter_type, filter_target_id, source_kind, source_config, trigger_kind, trigger_config, max_concurrency, workspace_name, agent_kind, enabled, created_at,
(SELECT count(*) FROM runs WHERE runs.pipe_id = pipes.id AND runs.state IN ('starting','running','blocked','recovering')) AS active_agents,
(SELECT state FROM runs WHERE runs.pipe_id = pipes.id ORDER BY updated_at DESC, id DESC LIMIT 1) AS latest_run_state
FROM pipes ORDER BY created_at DESC`));
if (request.method === "GET" && url.pathname.startsWith("/pipes/")) return await this.flowDetail(url.pathname.split("/")[2] ?? "");
if (request.method === "GET" && url.pathname === "/runs") return json(this.rows("SELECT id, pipe_id, issue_id, agent_name, state, created_at, updated_at FROM runs ORDER BY created_at DESC LIMIT 100"));
if (request.method === "GET" && url.pathname === "/v1/runs") return this.listRuns(url);
Expand Down
2 changes: 1 addition & 1 deletion src/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,6 @@ export const flowsPage = (viewer: { email: string }) => shell("My Flows — Fact
</main>`, `
const root=document.querySelector('#flows'),error=document.querySelector('#error');
const esc=v=>{const d=document.createElement('div');d.textContent=v??'';return d.innerHTML};
async function load(){const r=await fetch('/api/pipes');if(r.status===401)return location.href='/auth/linear';const flows=await r.json();if(!flows.length){root.innerHTML='<div class="p-10 text-center"><h2 class="font-semibold">No flows yet</h2><p class="mt-2 text-sm text-slate-500 dark:text-slate-400">Create one to start turning work into agent jobs.</p><a href="/flows/new" class="mt-5 inline-flex text-sm font-semibold text-factorize-700 dark:text-factorize-500">Create your first flow →</a></div>';return}root.innerHTML='<ul class="divide-y divide-stone-200 dark:divide-slate-800">'+flows.map(f=>{let label=f.source_kind==='github'?'GitHub merge-queue conflict':f.filter_type+' trigger';if(f.source_kind==='custom'){try{const s=JSON.parse(f.source_config||'{}');label='Custom · '+s.origin+' · '+s.handlerName}catch{label='Custom'}}return '<li class="flex items-center justify-between gap-5 p-5 sm:px-6"><div class="min-w-0"><a href="/flows/'+encodeURIComponent(f.id)+'" class="block truncate font-semibold hover:text-factorize-700 dark:hover:text-factorize-500">'+esc(f.name)+'</a><p class="mt-1 text-sm text-slate-500 dark:text-slate-400">'+esc(label)+' · '+esc(f.max_concurrency)+' concurrent</p></div><button data-delete="'+esc(f.id)+'" class="shrink-0 rounded-lg border border-stone-200 px-3 py-2 text-sm font-medium text-red-600 hover:bg-red-50 dark:border-slate-700 dark:text-red-400 dark:hover:bg-red-950/50">Delete</button></li>'}).join('')+'</ul>'}
async function load(){const r=await fetch('/api/pipes');if(r.status===401)return location.href='/auth/linear';const flows=await r.json();if(!flows.length){root.innerHTML='<div class="p-10 text-center"><h2 class="font-semibold">No flows yet</h2><p class="mt-2 text-sm text-slate-500 dark:text-slate-400">Create one to start turning work into agent jobs.</p><a href="/flows/new" class="mt-5 inline-flex text-sm font-semibold text-factorize-700 dark:text-factorize-500">Create your first flow →</a></div>';return}root.innerHTML='<ul class="divide-y divide-stone-200 dark:divide-slate-800">'+flows.map(f=>{const active=Number(f.active_agents)||0,state=active>0?'running':f.latest_run_state==='done'?'complete':f.latest_run_state==='failed'?'error':'idle',dot=state==='running'?'bg-green-500':state==='complete'?'bg-blue-500':state==='error'?'bg-red-500':'bg-slate-300 dark:bg-slate-600';return '<li class="flex items-center justify-between gap-5 p-5 sm:px-6"><div class="min-w-0"><a href="/flows/'+encodeURIComponent(f.id)+'" class="flex min-w-0 items-center gap-3 font-semibold hover:text-factorize-700 dark:hover:text-factorize-500"><span class="h-2.5 w-2.5 shrink-0 rounded-full '+dot+'" title="'+esc(state)+'"><span class="sr-only">'+esc(state)+'</span></span><span class="truncate">'+esc(f.name)+'</span></a><p class="mt-1 pl-5.5 text-sm text-slate-500 dark:text-slate-400">'+esc(active)+'/'+esc(f.max_concurrency)+' concurrent agents</p></div><button data-delete="'+esc(f.id)+'" class="shrink-0 rounded-lg border border-stone-200 px-3 py-2 text-sm font-medium text-red-600 hover:bg-red-50 dark:border-slate-700 dark:text-red-400 dark:hover:bg-red-950/50">Delete</button></li>'}).join('')+'</ul>'}
root.onclick=async e=>{const button=e.target.closest('[data-delete]');if(!button)return;if(!confirm('Delete this flow and stop Factorize from tracking its queued or running jobs? An agent already started on the VM will continue until you stop it there.'))return;button.disabled=true;const r=await fetch('/api/pipes/'+encodeURIComponent(button.dataset.delete),{method:'DELETE'});const result=await r.json().catch(()=>({}));if(!r.ok){error.textContent=result.error||'Could not delete the flow.';error.classList.remove('hidden');button.disabled=false;return}load()};load();
`);
13 changes: 12 additions & 1 deletion test/ui.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from "vitest";
import { flowDetailPage, flowPage, landingPage } from "../src/ui";
import { flowDetailPage, flowPage, flowsPage, landingPage } from "../src/ui";

describe("pages", () => {
const expectInlineScriptsToParse = (html: string) => {
Expand Down Expand Up @@ -71,6 +71,17 @@ describe("pages", () => {
expectInlineScriptsToParse(html);
});

it("renders flow status and active agent capacity without trigger details", () => {
const html = flowsPage({ email: "owner@example.com" });
expect(html).toContain("active_agents");
expect(html).toContain("bg-green-500");
expect(html).toContain("bg-blue-500");
expect(html).toContain("bg-red-500");
expect(html).toContain("concurrent agents");
expect(html).not.toContain("filter_type+' trigger'");
expectInlineScriptsToParse(html);
});

it("escapes profile data", () => {
const html = landingPage({ email: '<script>alert("x")</script>@example.com' });
expect(html).not.toContain('<script>alert("x")</script>@example.com');
Expand Down