/** * @file GET /api/sessions/:id/transcript keeps a long conversation turn whole: * the chat shows an assistant's answer and a user's prompt as they were, while * a tool's output — the part that can be megabytes — is still capped. * @author Nguyễn Ngọc Trí Vĩ */ const { describe, it, before, after } = require("node:test"); const assert = require("node:assert/strict"); const fs = require("fs"); const os = require("os"); const path = require("path"); const TMP = fs.mkdtempSync(path.join(os.tmpdir(), "agenthub-long-text-")); process.env.DASHBOARD_DB_PATH = path.join(TMP, "dashboard.db"); process.env.CLAUDE_HOME = path.join(TMP, "home"); process.env.DASHBOARD_DATA_DIR = path.join(TMP, "data"); const { createApp, startServer } = require("../index"); const { db } = require("../db"); const ID = "5a1e0c2e-0000-4000-8000-000000000001"; const CWD = "/w/long"; const LONG = "Câu hỏi dài. ".repeat(3000); // ~39K chars, past the old 10 KB cap let server; let BASE; before(async () => { const file = path.join( process.env.CLAUDE_HOME, "projects", CWD.replace(/[^a-zA-Z0-9]/g, "-"), `${ID}.jsonl` ); fs.mkdirSync(path.dirname(file), { recursive: true }); const lines = [ { type: "user", message: { role: "user", content: LONG } }, { type: "assistant", message: { role: "assistant", content: [ { type: "text", text: LONG }, { type: "tool_use", id: "t1", name: "Bash", input: { command: "cat big" } }, ], }, }, { type: "user", message: { role: "user", content: [{ type: "tool_result", tool_use_id: "t1", content: LONG }], }, }, ]; fs.writeFileSync(file, lines.map((l) => JSON.stringify(l)).join("\n") + "\n"); db.prepare("INSERT INTO sessions (id, status, cwd) VALUES (?, 'completed', ?)").run(ID, CWD); server = await startServer(createApp(), 0); BASE = `http://127.0.0.1:${server.address().port}`; }); after(() => { server?.close(); try { db.close(); } catch {} fs.rmSync(TMP, { recursive: true, force: true }); }); describe("transcript long text", () => { it("keeps a long prompt and answer whole and still caps a tool's output", async () => { const body = await (await fetch(`${BASE}/api/sessions/${ID}/transcript`)).json(); const [prompt, answer, result] = body.messages; assert.equal(prompt.content[0].text, LONG); assert.equal(answer.content[0].text, LONG); assert.ok(result.content[0].output.endsWith("[truncated]")); }); });