From 5f2cef7f80c19a48f2a3f60c1fc9d1c61a8f4694 Mon Sep 17 00:00:00 2001 From: Hsukqi Lee Date: Tue, 17 Nov 2026 03:51:10 +0800 Subject: [PATCH] fix: load and download complete paginated run logs --- .github/workflows/ci.yml | 6 ++++- web/package.json | 3 ++- web/src/api.ts | 11 ++++++++- web/src/components/LogsPanel.tsx | 25 +++++++++++++------- web/src/store.ts | 3 ++- web/tests/logs.test.ts | 40 ++++++++++++++++++++++++++++++++ 6 files changed, 75 insertions(+), 13 deletions(-) create mode 100644 web/tests/logs.test.ts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 688fc6a..665298a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -41,7 +41,7 @@ jobs: - name: Set up Node.js uses: actions/setup-node@v4 with: - node-version: "20" + node-version: "24.22.2" cache: npm cache-dependency-path: web/package-lock.json @@ -53,6 +53,10 @@ jobs: run: npm run build working-directory: web + - name: Verify paginated log retrieval + run: npm test + working-directory: web + - name: Set up Go uses: actions/setup-go@v5 with: diff --git a/web/package.json b/web/package.json index e2f8915..2c203fe 100644 --- a/web/package.json +++ b/web/package.json @@ -6,7 +6,8 @@ "scripts": { "dev": "vite", "build": "tsc -b && vite build && touch dist/.gitkeep", - "typecheck": "tsc -b" + "typecheck": "tsc -b", + "test": "node --experimental-transform-types --test tests/*.test.ts" }, "dependencies": { "@assistant-ui/react": "0.15.36", diff --git a/web/src/api.ts b/web/src/api.ts index 543a0de..4e1fb80 100644 --- a/web/src/api.ts +++ b/web/src/api.ts @@ -101,7 +101,16 @@ export const api = { run: (id: string) => req("GET", `/runs/${encodeURIComponent(id)}`), control: (id: string, action: "pause" | "resume" | "stop" | "retry" | "continue") => req("POST", `/runs/${encodeURIComponent(id)}/${action}`), - logs: (id: string, after = 0) => req("GET", `/runs/${encodeURIComponent(id)}/logs?after=${after}`), + logs: async (id: string, after = 0): Promise => { + const entries: LogEntry[] = []; + const limit = 5000; + for (;;) { + const page = await req("GET", `/runs/${encodeURIComponent(id)}/logs?after=${after}&limit=${limit}`); + entries.push(...page); + if (page.length < limit) return entries; + after = page[page.length - 1].seq; + } + }, tasks: () => req("GET", "/tasklib"), task: (name: string) => req("GET", `/tasklib/${encodeURIComponent(name)}`), diff --git a/web/src/components/LogsPanel.tsx b/web/src/components/LogsPanel.tsx index b78cfaf..a3effa8 100644 --- a/web/src/components/LogsPanel.tsx +++ b/web/src/components/LogsPanel.tsx @@ -1,7 +1,8 @@ import { useEffect, useMemo, useRef, useState } from "react"; import clsx from "clsx"; import { Download, X } from "lucide-react"; -import { useStore, closeLogs } from "../store"; +import { useStore, closeLogs, guard } from "../store"; +import { api } from "../api"; import type { LogEntry } from "../types"; const sources = [ @@ -29,6 +30,7 @@ export function LogsPanel() { const [step, setStep] = useState(panel?.stepId ?? ""); const [query, setQuery] = useState(""); const [follow, setFollow] = useState(true); + const [downloading, setDownloading] = useState(false); const ref = useRef(null); useEffect(() => setStep(panel?.stepId ?? ""), [panel?.runId, panel?.stepId]); @@ -49,13 +51,18 @@ export function LogsPanel() { if (!panel) return null; - const download = () => { - const text = logs.map((l) => `${l.time} [${l.source}]${l.stepId ? ` [${l.stepId}]` : ""} ${l.text}`).join("\n"); - const a = document.createElement("a"); - a.href = URL.createObjectURL(new Blob([text], { type: "text/plain" })); - a.download = `${panel.runId}.log`; - a.click(); - URL.revokeObjectURL(a.href); + const download = async () => { + setDownloading(true); + try { + const entries = await guard(api.logs(panel.runId)); + if (!entries) return; + const text = entries.map((l) => `${l.time} [${l.source}]${l.stepId ? ` [${l.stepId}]` : ""} ${l.text}`).join("\n"); + const a = document.createElement("a"); + a.href = URL.createObjectURL(new Blob([text], { type: "text/plain" })); + a.download = `${panel.runId}.log`; + a.click(); + URL.revokeObjectURL(a.href); + } finally { setDownloading(false); } }; return ( @@ -68,7 +75,7 @@ export function LogsPanel() { {run?.title} · {panel.runId} -