Skip to content

🙌 OpenHands: AI-Driven Development

feat: activity log export (#16234)

Shashwat Pratap Singh877e56a15399
diff --git a/__tests__/components/automations/detail/activity-log-section.test.tsx b/__tests__/components/automations/detail/activity-log-section.test.tsx
new file mode 100644
index 0000000000..7f89203ac0
--- /dev/null
+++ b/__tests__/components/automations/detail/activity-log-section.test.tsx
@@ -0,0 +1,129 @@
+import { render, screen, waitFor } from "@testing-library/react";
+import userEvent from "@testing-library/user-event";
+import { beforeEach, describe, expect, it, vi } from "vitest";
+import { ActivityLogSection } from "#/components/features/automations/detail/activity-log-section";
+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
+import {
+ AutomationRunStatus,
+ type Automation,
+ type AutomationRun,
+} from "#/types/automation";
+import { downloadActivityLogExport } from "#/utils/automation-activity-log-export";
+
+const { trackAutomationActivityLogExported } = vi.hoisted(() => ({
+ trackAutomationActivityLogExported: vi.fn(),
+}));
+
+vi.mock("#/utils/automation-activity-log-export", () => ({
+ downloadActivityLogExport: vi.fn().mockResolvedValue(undefined),
+}));
+
+vi.mock("#/hooks/use-tracking", () => ({
+ useTracking: () => ({
+ trackAutomationActivityLogExported,
+ }),
+}));
+
+vi.mock("#/contexts/active-backend-context", () => ({
+ useActiveBackend: () => ({
+ backend: { id: "default-local", kind: "local" },
+ orgId: null,
+ }),
+}));
+
+vi.mock("#/hooks/query/use-automation-detail", () => ({
+ useAutomationRuns: vi.fn(),
+}));
+
+import { useAutomationRuns } from "#/hooks/query/use-automation-detail";
+
+const automation: Automation = {
+ id: "a1",
+ name: "Test Activity Log",
+ trigger: { type: "cron", schedule: "0 9 * * 1-5", timezone: "UTC" },
+ enabled: true,
+ created_at: "2026-01-01T00:00:00Z",
+ updated_at: "2026-01-01T00:00:00Z",
+ prompt: "hello",
+};
+
+const run: AutomationRun = {
+ id: "r1",
+ status: AutomationRunStatus.COMPLETED,
+ conversation_id: "c1",
+ bash_command_id: "b1",
+ error_detail: null,
+ started_at: "2026-01-01T09:00:00Z",
+ completed_at: "2026-01-01T09:01:00Z",
+};
+
+function renderSection() {
+ const client = new QueryClient({
+ defaultOptions: { queries: { retry: false } },
+ });
+ return render(
+ <QueryClientProvider client={client}>
+ <ActivityLogSection automation={automation} />
+ </QueryClientProvider>,
+ );
+}
+
+describe("ActivityLogSection export", () => {
+ beforeEach(() => {
+ vi.clearAllMocks();
+ vi.mocked(useAutomationRuns).mockReturnValue({
+ data: { runs: [run], total: 1 },
+ isLoading: false,
+ } as unknown as ReturnType<typeof useAutomationRuns>);
+ });
+
+ it("exports JSON via the activity-log export helper and tracks it", async () => {
+ const user = userEvent.setup();
+ renderSection();
+
+ await user.click(screen.getByTestId("activity-log-export-json"));
+
+ await waitFor(() => {
+ expect(downloadActivityLogExport).toHaveBeenCalledWith({
+ automation,
+ format: "json",
+ conversationBaseUrl: window.location.origin,
+ });
+ });
+ expect(trackAutomationActivityLogExported).toHaveBeenCalledWith({
+ backendKind: "local",
+ format: "json",
+ });
+ });
+
+ it("exports CSV via the activity-log export helper and tracks it", async () => {
+ const user = userEvent.setup();
+ renderSection();
+
+ await user.click(screen.getByTestId("activity-log-export-csv"));
+
+ await waitFor(() => {
+ expect(downloadActivityLogExport).toHaveBeenCalledWith({
+ automation,
+ format: "csv",
+ conversationBaseUrl: window.location.origin,
+ });
+ });
+ expect(trackAutomationActivityLogExported).toHaveBeenCalledWith({
+ backendKind: "local",
+ format: "csv",
+ });
+ });
+
+ it("disables export when there are no runs", () => {
+ vi.mocked(useAutomationRuns).mockReturnValue({
+ data: { runs: [], total: 0 },
+ isLoading: false,
+ } as unknown as ReturnType<typeof useAutomationRuns>);
+
+ renderSection();
+
+ expect(screen.getByTestId("activity-log-export-json")).toBeDisabled();
+ expect(screen.getByTestId("activity-log-export-csv")).toBeDisabled();
+ });
+});
diff --git a/__tests__/utils/automation-activity-log-export.test.ts b/__tests__/utils/automation-activity-log-export.test.ts
new file mode 100644
index 0000000000..5a17fd92cd
--- /dev/null
+++ b/__tests__/utils/automation-activity-log-export.test.ts
@@ -0,0 +1,192 @@
+import { describe, it, expect, vi, beforeEach } from "vitest";
+import AutomationService from "#/api/automation-service/automation-service.api";
+import {
+ getActivityLogExportFilename,
+ serializeActivityLogRowsCsv,
+ mapAutomationRunToExportRow,
+ fetchAllActivityLogExportRows,
+ downloadActivityLogExport,
+} from "#/utils/automation-activity-log-export";
+import {
+ AutomationRunStatus,
+ type Automation,
+ type AutomationRun,
+ type AutomationRunExportRow,
+} from "#/types/automation";
+import { downloadBlob } from "#/utils/utils";
+
+vi.mock("#/api/automation-service/automation-service.api", () => ({
+ default: {
+ listAutomationRuns: vi.fn(),
+ },
+}));
+
+vi.mock("#/utils/utils", () => ({
+ downloadBlob: vi.fn(),
+}));
+
+const automation: Pick<Automation, "id" | "name" | "trigger"> = {
+ id: "a1",
+ name: "Test",
+ trigger: { type: "cron", schedule: "0 9 * * *" },
+};
+
+const sampleRun = (overrides: Partial<AutomationRun> = {}): AutomationRun => ({
+ id: "r1",
+ status: AutomationRunStatus.FAILED,
+ conversation_id: "c1",
+ bash_command_id: null,
+ error_detail: "boom",
+ started_at: "2026-01-01T09:00:00Z",
+ completed_at: "2026-01-01T09:01:00Z",
+ ...overrides,
+});
+
+const sampleRow = (
+ overrides: Partial<AutomationRunExportRow> = {},
+): AutomationRunExportRow => ({
+ run_id: "r1",
+ automation_id: "a1",
+ automation_name: "Test",
+ trigger: { type: "cron", schedule: "0 9 * * *" },
+ start_time: "2026-01-01T09:00:00Z",
+ end_time: "2026-01-01T09:01:00Z",
+ duration_seconds: 60,
+ status: AutomationRunStatus.FAILED,
+ conversation_id: "c1",
+ conversation_url: "http://localhost:8000/conversations/c1",
+ error: "boom",
+ ...overrides,
+});
+
+describe("automation-activity-log-export", () => {
+ beforeEach(() => {
+ vi.clearAllMocks();
+ });
+
+ it("builds a slug filename", () => {
+ expect(
+ getActivityLogExportFilename(
+ { id: "abc", name: "Test Activity Log" },
+ "json",
+ ),
+ ).toBe("test-activity-log.activity-log.json");
+ });
+
+ it("falls back to automation id when name has no slug chars", () => {
+ expect(
+ getActivityLogExportFilename({ id: "abc-123", name: "!!!" }, "csv"),
+ ).toBe("abc-123.activity-log.csv");
+ });
+
+ it("maps a list run into an export row with conversation URL and duration", () => {
+ expect(
+ mapAutomationRunToExportRow(
+ sampleRun(),
+ automation,
+ "http://localhost:8000",
+ ),
+ ).toEqual(sampleRow());
+ });
+
+ it("serializes CSV with conversation URL and escaped fields", () => {
+ const rows: AutomationRunExportRow[] = [
+ sampleRow({
+ error: 'said "boom", then failed',
+ }),
+ ];
+
+ const csv = serializeActivityLogRowsCsv(rows);
+ expect(csv.split("\n")[0]).toContain("conversation_url");
+ expect(csv).toContain("http://localhost:8000/conversations/c1");
+ expect(csv).toContain("FAILED");
+ expect(csv).toContain('"said ""boom"", then failed"');
+ expect(csv).toContain('"{""type"":""cron"",""schedule"":""0 9 * * *""}"');
+ });
+
+ it("pages listAutomationRuns until complete", async () => {
+ vi.mocked(AutomationService.listAutomationRuns)
+ .mockResolvedValueOnce({
+ runs: [sampleRun({ id: "r1" })],
+ total: 2,
+ })
+ .mockResolvedValueOnce({
+ runs: [sampleRun({ id: "r2", conversation_id: "c2" })],
+ total: 2,
+ });
+
+ const rows = await fetchAllActivityLogExportRows(
+ automation,
+ "http://localhost:8000",
+ );
+
+ expect(rows).toHaveLength(2);
+ expect(rows[0].run_id).toBe("r1");
+ expect(rows[1].run_id).toBe("r2");
+ expect(rows[1].conversation_url).toBe(
+ "http://localhost:8000/conversations/c2",
+ );
+ expect(AutomationService.listAutomationRuns).toHaveBeenCalledTimes(2);
+ expect(AutomationService.listAutomationRuns).toHaveBeenNthCalledWith(1, "a1", {
+ limit: 100,
+ offset: 0,
+ });
+ expect(AutomationService.listAutomationRuns).toHaveBeenNthCalledWith(2, "a1", {
+ limit: 100,
+ offset: 1,
+ });
+ });
+
+ it("downloads JSON after paging list runs", async () => {
+ vi.mocked(AutomationService.listAutomationRuns).mockResolvedValueOnce({
+ runs: [
+ sampleRun({
+ status: AutomationRunStatus.COMPLETED,
+ error_detail: null,
+ }),
+ ],
+ total: 1,
+ });
+
+ await downloadActivityLogExport({
+ automation,
+ format: "json",
+ conversationBaseUrl: "http://localhost:8000",
+ });
+
+ expect(AutomationService.listAutomationRuns).toHaveBeenCalledWith("a1", {
+ limit: 100,
+ offset: 0,
+ });
+ expect(downloadBlob).toHaveBeenCalledWith(
+ expect.any(Blob),
+ "test.activity-log.json",
+ );
+ const blob = vi.mocked(downloadBlob).mock.calls[0][0] as Blob;
+ expect(blob.type).toBe("application/json");
+ });
+
+ it("downloads CSV after paging list runs", async () => {
+ vi.mocked(AutomationService.listAutomationRuns).mockResolvedValueOnce({
+ runs: [sampleRun()],
+ total: 1,
+ });
+
+ await downloadActivityLogExport({
+ automation,
+ format: "csv",
+ conversationBaseUrl: "http://localhost:8000",
+ });
+
+ expect(AutomationService.listAutomationRuns).toHaveBeenCalledWith("a1", {
+ limit: 100,
+ offset: 0,
+ });
+ expect(downloadBlob).toHaveBeenCalledWith(
+ expect.any(Blob),
+ "test.activity-log.csv",
+ );
+ const blob = vi.mocked(downloadBlob).mock.calls[0][0] as Blob;
+ expect(blob.type).toBe("text/csv;charset=utf-8");
+ });
+});
diff --git a/src/components/features/automations/detail/activity-log-section.tsx b/src/components/features/automations/detail/activity-log-section.tsx
index 37712273ef..3458340928 100644
--- a/src/components/features/automations/detail/activity-log-section.tsx
+++ b/src/components/features/automations/detail/activity-log-section.tsx
@@ -2,9 +2,14 @@ import { useState } from "react";
import { useTranslation } from "react-i18next";
import { I18nKey } from "#/i18n/declaration";
import { useAutomationRuns } from "#/hooks/query/use-automation-detail";
+import { useActiveBackend } from "#/contexts/active-backend-context";
+import { useTracking } from "#/hooks/use-tracking";
import ActivityIcon from "#/icons/activity.svg?react";
+import { displayErrorToast } from "#/utils/custom-toast-handlers";
+import { getApiErrorMessage } from "#/utils/api-error-message";
+import { downloadActivityLogExport } from "#/utils/automation-activity-log-export";
+import type { ActivityLogExportFormat, Automation } from "#/types/automation";
import { ActivityLogItem } from "./activity-log-item";
-import type { Automation } from "#/types/automation";
interface ActivityLogSectionProps {
automation: Automation;
@@ -14,7 +19,10 @@ const PAGE_SIZE = 20;
export function ActivityLogSection({ automation }: ActivityLogSectionProps) {
const { t } = useTranslation("openhands");
+ const active = useActiveBackend();
+ const { trackAutomationActivityLogExported } = useTracking();
const [limit, setLimit] = useState(PAGE_SIZE);
+ const [isExporting, setIsExporting] = useState(false);
const { data, isLoading } = useAutomationRuns({
id: automation.id,
limit,
@@ -22,6 +30,32 @@ export function ActivityLogSection({ automation }: ActivityLogSectionProps) {
});
const hasMore = data ? data.total > data.runs.length : false;
+ const canExport = !isLoading && (data?.total ?? 0) > 0 && !isExporting;
+
+ const handleExport = async (format: ActivityLogExportFormat) => {
+ if (!canExport) return;
+ setIsExporting(true);
+ try {
+ await downloadActivityLogExport({
+ automation,
+ format,
+ conversationBaseUrl: window.location.origin,
+ });
+ trackAutomationActivityLogExported({
+ backendKind: active.backend.kind,
+ format,
+ });
+ } catch (error) {
+ displayErrorToast(
+ getApiErrorMessage(
+ error,
+ t(I18nKey.AUTOMATIONS$DETAIL$EXPORT_ACTIVITY_LOG_ERROR),
+ ),
+ );
+ } finally {
+ setIsExporting(false);
+ }
+ };
return (
<div className="rounded-2xl border border-[var(--oh-border)] bg-[var(--oh-surface)]">
@@ -32,6 +66,26 @@ export function ActivityLogSection({ automation }: ActivityLogSectionProps) {
<h3 className="text-sm font-medium text-content">
{t(I18nKey.AUTOMATIONS$DETAIL$ACTIVITY_LOG)}
</h3>
+ <div className="ml-auto flex items-center gap-3">
+ <button
+ type="button"
+ data-testid="activity-log-export-json"
+ disabled={!canExport}
+ onClick={() => void handleExport("json")}
+ className="text-sm text-muted hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50"
+ >
+ {t(I18nKey.AUTOMATIONS$DETAIL$EXPORT_JSON)}
+ </button>
+ <button
+ type="button"
+ data-testid="activity-log-export-csv"
+ disabled={!canExport}
+ onClick={() => void handleExport("csv")}
+ className="text-sm text-muted hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50"
+ >
+ {t(I18nKey.AUTOMATIONS$DETAIL$EXPORT_CSV)}
+ </button>
+ </div>
</div>
{isLoading && (
diff --git a/src/hooks/use-tracking.ts b/src/hooks/use-tracking.ts
index 6103e3f73f..fb17522104 100644
--- a/src/hooks/use-tracking.ts
+++ b/src/hooks/use-tracking.ts
@@ -301,6 +301,19 @@ export const useTracking = () => {
track("automation_exported", { backend_kind: backendKind });
};
+ const trackAutomationActivityLogExported = ({
+ backendKind,
+ format,
+ }: {
+ backendKind: BackendKind;
+ format: "json" | "csv";
+ }) => {
+ track("automation_activity_log_exported", {
+ backend_kind: backendKind,
+ format,
+ });
+ };
+
const trackAutomationImported = ({
backendKind,
}: {
@@ -407,6 +420,7 @@ export const useTracking = () => {
trackAutomationDisableButton,
trackAutomationEdited,
trackAutomationExported,
+ trackAutomationActivityLogExported,
trackAutomationImported,
trackBackendAdded,
trackOnboardingStarted,
diff --git a/src/i18n/translation.json b/src/i18n/translation.json
index 88580560da..638a4d3dbd 100644
--- a/src/i18n/translation.json
+++ b/src/i18n/translation.json
@@ -14245,6 +14245,57 @@
"uk": "Завантажити більше",
"ca": "Carrega'n més"
},
+ "AUTOMATIONS$DETAIL$EXPORT_JSON": {
+ "en": "Export JSON",
+ "ja": "JSONをエクスポート",
+ "zh-CN": "导出 JSON",
+ "zh-TW": "匯出 JSON",
+ "ko-KR": "JSON 내보내기",
+ "no": "Eksporter JSON",
+ "it": "Esporta JSON",
+ "pt": "Exportar JSON",
+ "es": "Exportar JSON",
+ "ar": "تصدير JSON",
+ "fr": "Exporter JSON",
+ "tr": "JSON dışa aktar",
+ "de": "JSON exportieren",
+ "uk": "Експортувати JSON",
+ "ca": "Exporta JSON"
+ },
+ "AUTOMATIONS$DETAIL$EXPORT_CSV": {
+ "en": "Export CSV",
+ "ja": "CSVをエクスポート",
+ "zh-CN": "导出 CSV",
+ "zh-TW": "匯出 CSV",
+ "ko-KR": "CSV 내보내기",
+ "no": "Eksporter CSV",
+ "it": "Esporta CSV",
+ "pt": "Exportar CSV",
+ "es": "Exportar CSV",
+ "ar": "تصدير CSV",
+ "fr": "Exporter CSV",
+ "tr": "CSV dışa aktar",
+ "de": "CSV exportieren",
+ "uk": "Експортувати CSV",
+ "ca": "Exporta CSV"
+ },
+ "AUTOMATIONS$DETAIL$EXPORT_ACTIVITY_LOG_ERROR": {
+ "en": "Failed to export activity log",
+ "ja": "アクティビティログのエクスポートに失敗しました",
+ "zh-CN": "导出活动日志失败",
+ "zh-TW": "匯出活動紀錄失敗",
+ "ko-KR": "활동 로그 내보내기에 실패했습니다",
+ "no": "Kunne ikke eksportere aktivitetslogg",
+ "it": "Esportazione del registro attività non riuscita",
+ "pt": "Falha ao exportar o registo de atividade",
+ "es": "Error al exportar el registro de actividad",
+ "ar": "فشل تصدير سجل النشاط",
+ "fr": "Échec de l'export du journal d'activité",
+ "tr": "Etkinlik günlüğü dışa aktarılamadı",
+ "de": "Aktivitätsprotokoll konnte nicht exportiert werden",
+ "uk": "Не вдалося експортувати журнал активності",
+ "ca": "No s'ha pogut exportar el registre d'activitat"
+ },
"AUTOMATIONS$DETAIL$MODEL": {
"en": "LLM profile",
"ja": "モデル",
diff --git a/src/mocks/automation-handlers.ts b/src/mocks/automation-handlers.ts
index c71894b13b..f8cf8cfc47 100644
--- a/src/mocks/automation-handlers.ts
+++ b/src/mocks/automation-handlers.ts
@@ -214,7 +214,6 @@ export const AUTOMATION_HANDLERS = [
const url = new URL(request.url);
const limit = Number(url.searchParams.get("limit") ?? "50");
const offset = Number(url.searchParams.get("offset") ?? "0");
-
const allRuns = MOCK_AUTOMATION_RUNS[id] ?? [];
const page = allRuns.slice(offset, offset + limit);
diff --git a/src/types/automation.ts b/src/types/automation.ts
index ba3e3d5f13..31609ad240 100644
--- a/src/types/automation.ts
+++ b/src/types/automation.ts
@@ -93,3 +93,20 @@ export interface AutomationRunsResponse {
runs: AutomationRun[];
total: number;
}
+
+export type ActivityLogExportFormat = "json" | "csv";
+
+/** Client-built Activity Log export row (from list runs + automation detail). */
+export interface AutomationRunExportRow {
+ run_id: string;
+ automation_id: string;
+ automation_name: string;
+ trigger: AutomationTrigger | Record<string, unknown>;
+ start_time: string | null;
+ end_time: string | null;
+ duration_seconds: number | null;
+ status: AutomationRunStatus;
+ conversation_id: string | null;
+ conversation_url: string | null;
+ error: string | null;
+}
diff --git a/src/utils/automation-activity-log-export.ts b/src/utils/automation-activity-log-export.ts
new file mode 100644
index 0000000000..31f308155b
--- /dev/null
+++ b/src/utils/automation-activity-log-export.ts
@@ -0,0 +1,165 @@
+import type {
+ ActivityLogExportFormat,
+ Automation,
+ AutomationRun,
+ AutomationRunExportRow,
+} from "#/types/automation";
+import { downloadBlob } from "#/utils/utils";
+import AutomationService from "#/api/automation-service/automation-service.api";
+
+const EXPORT_PAGE_SIZE = 100;
+
+const CSV_COLUMNS = [
+ "run_id",
+ "automation_id",
+ "automation_name",
+ "trigger",
+ "start_time",
+ "end_time",
+ "duration_seconds",
+ "status",
+ "conversation_id",
+ "conversation_url",
+ "error",
+] as const;
+
+export function getActivityLogExportFilename(
+ automation: Pick<Automation, "id" | "name">,
+ format: ActivityLogExportFormat,
+): string {
+ const slug = automation.name
+ .trim()
+ .toLowerCase()
+ .replace(/[^a-z0-9]+/g, "-")
+ .replace(/^-+|-+$/g, "");
+ return `${slug || automation.id}.activity-log.${format}`;
+}
+
+function csvEscape(value: string): string {
+ if (/[",\n\r]/.test(value)) {
+ return `"${value.replace(/"/g, '""')}"`;
+ }
+ return value;
+}
+
+export function serializeActivityLogRowsCsv(
+ rows: AutomationRunExportRow[],
+): string {
+ const lines: string[] = [CSV_COLUMNS.join(",")];
+ for (const row of rows) {
+ const values = CSV_COLUMNS.map((key) => {
+ const raw = row[key];
+ if (raw == null) return "";
+ if (key === "trigger") {
+ return csvEscape(JSON.stringify(raw));
+ }
+ return csvEscape(String(raw));
+ });
+ lines.push(values.join(","));
+ }
+ return `${lines.join("\n")}\n`;
+}
+
+export function buildConversationUrl(
+ conversationId: string | null,
+ conversationBaseUrl?: string,
+): string | null {
+ if (!conversationId) return null;
+ const path = `/conversations/${conversationId}`;
+ if (!conversationBaseUrl) return path;
+ return `${conversationBaseUrl.replace(/\/$/, "")}${path}`;
+}
+
+export function mapAutomationRunToExportRow(
+ run: AutomationRun,
+ automation: Pick<Automation, "id" | "name" | "trigger">,
+ conversationBaseUrl?: string,
+): AutomationRunExportRow {
+ const start = run.started_at || null;
+ const end = run.completed_at;
+ let duration_seconds: number | null = null;
+ if (start && end) {
+ duration_seconds =
+ (new Date(end).getTime() - new Date(start).getTime()) / 1000;
+ }
+
+ return {
+ run_id: run.id,
+ automation_id: automation.id,
+ automation_name: automation.name,
+ trigger: automation.trigger,
+ start_time: start,
+ end_time: end,
+ duration_seconds,
+ status: run.status,
+ conversation_id: run.conversation_id,
+ conversation_url: buildConversationUrl(
+ run.conversation_id,
+ conversationBaseUrl,
+ ),
+ error: run.error_detail,
+ };
+}
+
+/**
+ * Page ``GET /v1/{id}/runs`` until complete, then project export rows locally.
+ */
+export async function fetchAllActivityLogExportRows(
+ automation: Pick<Automation, "id" | "name" | "trigger">,
+ conversationBaseUrl?: string,
+): Promise<AutomationRunExportRow[]> {
+ const rows: AutomationRunExportRow[] = [];
+ let offset = 0;
+ let total = Number.POSITIVE_INFINITY;
+
+ while (offset < total) {
+ const page = await AutomationService.listAutomationRuns(automation.id, {
+ limit: EXPORT_PAGE_SIZE,
+ offset,
+ });
+
+ for (const run of page.runs) {
+ rows.push(
+ mapAutomationRunToExportRow(run, automation, conversationBaseUrl),
+ );
+ }
+ total = page.total;
+ offset += page.runs.length;
+ if (page.runs.length === 0) break;
+ }
+
+ return rows;
+}
+
+/**
+ * Page the runs list endpoint and download one CSV or JSON file.
+ */
+export async function downloadActivityLogExport(options: {
+ automation: Pick<Automation, "id" | "name" | "trigger">;
+ format: ActivityLogExportFormat;
+ conversationBaseUrl?: string;
+}): Promise<void> {
+ const { automation, format, conversationBaseUrl } = options;
+ const rows = await fetchAllActivityLogExportRows(
+ automation,
+ conversationBaseUrl,
+ );
+
+ if (format === "json") {
+ downloadBlob(
+ new Blob(
+ [`${JSON.stringify({ runs: rows, total: rows.length }, null, 2)}\n`],
+ { type: "application/json" },
+ ),
+ getActivityLogExportFilename(automation, "json"),
+ );
+ return;
+ }
+
+ downloadBlob(
+ new Blob([serializeActivityLogRowsCsv(rows)], {
+ type: "text/csv;charset=utf-8",
+ }),
+ getActivityLogExportFilename(automation, "csv"),
+ );
+}