leedab 0.1.7 → 0.1.9

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.
@@ -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
- // If session is a UUID, use it directly; otherwise search by key
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 { stdout } = await execFileAsync(bin, ["sessions", "--json"], { env: openclawEnv(stateDir), timeout: 10000 });
234
- const parsed = JSON.parse(stdout);
235
- const sessions = parsed.sessions ?? (Array.isArray(parsed) ? parsed : []);
236
- json(res, sessions);
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, []);
package/dist/license.js CHANGED
@@ -4,6 +4,7 @@ import { STATE_DIR } from "./paths.js";
4
4
  const LICENSE_PATH = resolve(STATE_DIR, "license.json");
5
5
  const VERIFY_URL = "https://api.leedab.com/api/v1/licensing/verify";
6
6
  const REVALIDATE_DAYS = 7;
7
+ const REVALIDATE_DAYS_TRIAL = 1;
7
8
  /**
8
9
  * Validate a license key against the API.
9
10
  */
@@ -63,7 +64,8 @@ function isStale(license) {
63
64
  const validated = new Date(license.validatedAt).getTime();
64
65
  const now = Date.now();
65
66
  const daysSince = (now - validated) / (1000 * 60 * 60 * 24);
66
- return daysSince > REVALIDATE_DAYS;
67
+ const maxDays = license.status === "trialing" ? REVALIDATE_DAYS_TRIAL : REVALIDATE_DAYS;
68
+ return daysSince > maxDays;
67
69
  }
68
70
  /**
69
71
  * Ensure we have a valid license. Returns the license if valid.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "leedab",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "description": "LeedAB — Your enterprise AI agent. Local-first, private by default.",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "author": "LeedAB <hello@leedab.com>",