leedab 0.1.7 → 0.1.8
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/dist/dashboard/routes.js +42 -22
- package/package.json +1 -1
package/dist/dashboard/routes.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { execFile, spawn } from "node:child_process";
|
|
2
|
-
import { readFile, writeFile, mkdir, readdir } from "node:fs/promises";
|
|
2
|
+
import { readFile, writeFile, mkdir, readdir, stat } from "node:fs/promises";
|
|
3
3
|
import { resolve } from "node:path";
|
|
4
4
|
import { promisify } from "node:util";
|
|
5
5
|
import { userInfo } from "node:os";
|
|
@@ -74,23 +74,7 @@ export function createRoutes(config) {
|
|
|
74
74
|
const session = url.searchParams.get("session") ?? "console";
|
|
75
75
|
try {
|
|
76
76
|
const sessionsDir = resolve(stateDir, "agents", "main", "sessions");
|
|
77
|
-
|
|
78
|
-
let jsonlPath = resolve(sessionsDir, `${session}.jsonl`);
|
|
79
|
-
// Try to find the file — if not found by direct name, scan directory
|
|
80
|
-
try {
|
|
81
|
-
await readFile(jsonlPath);
|
|
82
|
-
}
|
|
83
|
-
catch {
|
|
84
|
-
// Session param might be the key rather than the UUID filename
|
|
85
|
-
// List files and try to match
|
|
86
|
-
const files = await readdir(sessionsDir);
|
|
87
|
-
const match = files.find(f => f.endsWith(".jsonl"));
|
|
88
|
-
if (!match) {
|
|
89
|
-
json(res, []);
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
// Fall back to direct path — if it doesn't exist, we'll catch below
|
|
93
|
-
}
|
|
77
|
+
const jsonlPath = resolve(sessionsDir, `${session}.jsonl`);
|
|
94
78
|
const raw = await readFile(jsonlPath, "utf-8");
|
|
95
79
|
const messages = [];
|
|
96
80
|
for (const line of raw.split("\n")) {
|
|
@@ -230,10 +214,46 @@ export function createRoutes(config) {
|
|
|
230
214
|
*/
|
|
231
215
|
"GET /api/sessions": async (_req, res) => {
|
|
232
216
|
try {
|
|
233
|
-
const
|
|
234
|
-
|
|
235
|
-
const
|
|
236
|
-
|
|
217
|
+
const sessionsDir = resolve(stateDir, "agents", "main", "sessions");
|
|
218
|
+
// Get indexed sessions from openclaw, keyed by sessionId
|
|
219
|
+
const indexed = new Map();
|
|
220
|
+
try {
|
|
221
|
+
const { stdout } = await execFileAsync(bin, ["sessions", "--json"], { env: openclawEnv(stateDir), timeout: 10000 });
|
|
222
|
+
const parsed = JSON.parse(stdout);
|
|
223
|
+
for (const s of parsed.sessions ?? (Array.isArray(parsed) ? parsed : [])) {
|
|
224
|
+
if (s.sessionId)
|
|
225
|
+
indexed.set(s.sessionId, s);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
catch { }
|
|
229
|
+
// Walk JSONL files on disk — this is the source of truth
|
|
230
|
+
const results = [];
|
|
231
|
+
const files = await readdir(sessionsDir);
|
|
232
|
+
for (const f of files) {
|
|
233
|
+
if (!f.endsWith(".jsonl"))
|
|
234
|
+
continue;
|
|
235
|
+
const name = f.replace(/\.jsonl$/, "");
|
|
236
|
+
const entry = indexed.get(name);
|
|
237
|
+
if (entry) {
|
|
238
|
+
results.push(entry);
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
// Unindexed file (e.g. console.jsonl) — build minimal metadata
|
|
242
|
+
try {
|
|
243
|
+
const fstat = await stat(resolve(sessionsDir, f));
|
|
244
|
+
results.push({
|
|
245
|
+
key: `agent:main:${name}`,
|
|
246
|
+
sessionId: name,
|
|
247
|
+
updatedAt: fstat.mtimeMs,
|
|
248
|
+
chatType: "direct",
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
catch { }
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
// Sort newest first
|
|
255
|
+
results.sort((a, b) => (b.updatedAt ?? 0) - (a.updatedAt ?? 0));
|
|
256
|
+
json(res, results);
|
|
237
257
|
}
|
|
238
258
|
catch {
|
|
239
259
|
json(res, []);
|