@m8i-51/shoal 0.1.14 → 0.1.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/server/index.ts CHANGED
@@ -7,6 +7,7 @@ import { existsSync, readFileSync, writeFileSync } from "fs";
7
7
  import { listRuns, getReportPath } from "./runs.js";
8
8
  import { activeSessions, spawnRun, cancelSession } from "./runner.js";
9
9
  import { loadSchedule, saveSchedule, startScheduler, type ScheduleConfig } from "./scheduler.js";
10
+ import { generateDiary, getDiaryPath } from "../framework/diary.js";
10
11
 
11
12
  function specFilePath(baseUrl: string): string {
12
13
  try {
@@ -90,6 +91,43 @@ app.get("/api/runs", (_req, res) => {
90
91
  res.json(enriched);
91
92
  });
92
93
 
94
+ // ----------------------------------------------------------------
95
+ // API: diary for a run
96
+ // ----------------------------------------------------------------
97
+ app.get("/api/runs/:runId/diary", (req, res) => {
98
+ const { runId } = req.params;
99
+ if (!isValidRunId(runId)) { res.status(400).json({ error: "invalid run id" }); return; }
100
+ const p = getDiaryPath(runId);
101
+ if (!p) { res.status(404).json({ error: "diary not found" }); return; }
102
+ res.json({ content: readFileSync(p, "utf-8") });
103
+ });
104
+
105
+ app.post("/api/runs/:runId/diary", async (req, res) => {
106
+ const { runId } = req.params;
107
+ if (!isValidRunId(runId)) { res.status(400).json({ error: "invalid run id" }); return; }
108
+
109
+ const session = activeSessions.get(runId);
110
+ let lines: string[];
111
+ if (session) {
112
+ lines = session.lines;
113
+ } else {
114
+ const logFilePath = safeLogPath(`log_${runId}.txt`);
115
+ if (!logFilePath || !existsSync(logFilePath)) {
116
+ res.status(404).json({ error: "no log found" });
117
+ return;
118
+ }
119
+ lines = readFileSync(logFilePath, "utf-8").split("\n").filter((l) => l !== "");
120
+ }
121
+
122
+ try {
123
+ const content = await generateDiary(runId, lines);
124
+ res.json({ content });
125
+ } catch (err) {
126
+ console.error("[diary] generation failed:", err);
127
+ res.status(500).json({ error: "diary generation failed" });
128
+ }
129
+ });
130
+
93
131
  // ----------------------------------------------------------------
94
132
  // API: serve HTML report for a run
95
133
  // ----------------------------------------------------------------