Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(cli): preserve widget and app text in Markdown exports

Afloatec35541ec8dc
diff --git a/server/headless/export.test.ts b/server/headless/export.test.ts
index 02ca91cd90..eecbfe27a7 100644
--- a/server/headless/export.test.ts
+++ b/server/headless/export.test.ts
@@ -7,6 +7,9 @@ import { tmpdir } from "node:os";
import { join } from "node:path";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
+import { htmlFallbackText } from "../../shared/app.ts";
+import { parseWidgetInput, widgetToText } from "../../shared/widget.ts";
+import { WIDGET_SAMPLES } from "../../shared/widget-samples.ts";
import { removeTempDir } from "../testing/cleanup.ts";
import type { HeadlessIo } from "./output.ts";
import { safeName } from "./export.ts";
@@ -204,6 +207,30 @@ describe("export", () => {
expect(safeName("console.md")).toBe("console.md");
});
+ it.each(["widget", "app"])("keeps %s fallback text in the Markdown transcript", async (kind) => {
+ const parsed = parseWidgetInput(WIDGET_SAMPLES.pullRequests);
+ if (!parsed.ok) throw new Error(parsed.error);
+ const text = kind === "widget" ? widgetToText(parsed.value) : htmlFallbackText("Sales by month", "<h1>Sales</h1><p>Up 12%</p>");
+ const out = join(dir, kind);
+ const lead = messages[LEAD]!;
+ messages[LEAD] = [
+ { id: "before", role: "user", kind: "text", text: "Show the result" },
+ { id: "card", role: "bot", kind, text },
+ { id: "after", role: "user", kind: "text", text: "Thanks for the result" },
+ ];
+ try {
+ expect((await run(["export", "--thread", LEAD, "--out", out, "--json"])).code).toBe(0);
+ } finally {
+ messages[LEAD] = lead;
+ }
+ const transcript = JSON.parse(readFileSync(join(out, "transcripts/conversation-lead-thr.json"), "utf8"));
+ expect(transcript.messages[1]).toMatchObject({ kind, text });
+ const markdown = readFileSync(join(out, "transcripts/conversation-lead-thr.md"), "utf8");
+ expect(markdown).toContain(`**Room Lead:**\n\n${text}`);
+ expect(markdown.indexOf(text)).toBeGreaterThan(markdown.indexOf("Show the result"));
+ expect(markdown.indexOf("Thanks for the result")).toBeGreaterThan(markdown.indexOf(text));
+ });
+
it("keeps one job of the conversation with --root, and says so when there is none", async () => {
const missing = await run(["export", "--thread", LEAD, "--out", join(dir, "none"), "--root", "nope", "--json"]);
expect(missing).toMatchObject({ code: 2, result: { error: "no job with root nope in this conversation" } });
diff --git a/server/headless/export.ts b/server/headless/export.ts
index c12c4b006a..a43145370f 100644
--- a/server/headless/export.ts
+++ b/server/headless/export.ts
@@ -73,7 +73,7 @@ function markdownOf(title: string, messages: readonly Rec[], botName: string): s
const who = message.role === "user"
? `${message.sender?.name ?? "User"}${message.via === "api" ? " (via the local API)" : ""}`
: message.from?.name ?? botName;
- if (message.kind === "text" && message.text) lines.push(`**${who}:**`, "", String(message.text), "");
+ if ((message.kind === "text" || message.kind === "widget" || message.kind === "app") && message.text) lines.push(`**${who}:**`, "", String(message.text), "");
else if (message.kind === "activity" && message.tool) lines.push(`> ${message.tool.name}`, "");
else if (message.kind === "screen") lines.push("> [screen capture]", "");
else if (message.kind === "options" && message.card) lines.push(`> ${message.card.title}${message.card.answered ? ` — answered: ${message.card.answered}` : ""}`, "");