@sesamespace/hivemind 0.5.14 → 0.5.15

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,10 +1,10 @@
1
1
  import {
2
2
  Watchdog
3
- } from "./chunk-AGFKYYWT.js";
3
+ } from "./chunk-JV3WKYNF.js";
4
4
  import {
5
5
  defaultSentinelConfig,
6
6
  loadConfig
7
- } from "./chunk-QAOBO4W4.js";
7
+ } from "./chunk-MKVGEXKO.js";
8
8
 
9
9
  // packages/cli/src/commands/watchdog.ts
10
10
  import { resolve } from "path";
@@ -76,4 +76,4 @@ Options:
76
76
  export {
77
77
  runWatchdogCommand
78
78
  };
79
- //# sourceMappingURL=chunk-YMQR5I6C.js.map
79
+ //# sourceMappingURL=chunk-2EUG64XE.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  FleetManager
3
- } from "./chunk-AGFKYYWT.js";
3
+ } from "./chunk-JV3WKYNF.js";
4
4
 
5
5
  // packages/cli/src/commands/fleet.ts
6
6
  function formatUptime(seconds) {
@@ -183,4 +183,4 @@ Commands:
183
183
  export {
184
184
  runFleetCommand
185
185
  };
186
- //# sourceMappingURL=chunk-TRXLCIB4.js.map
186
+ //# sourceMappingURL=chunk-C5Y74B6I.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  startPipeline
3
- } from "./chunk-QAOBO4W4.js";
3
+ } from "./chunk-MKVGEXKO.js";
4
4
 
5
5
  // packages/cli/src/commands/start.ts
6
6
  import { resolve } from "path";
@@ -66,4 +66,4 @@ Options:
66
66
  export {
67
67
  runStartCommand
68
68
  };
69
- //# sourceMappingURL=chunk-7GZ545B5.js.map
69
+ //# sourceMappingURL=chunk-JFYYHCXR.js.map
@@ -6,7 +6,7 @@ import {
6
6
  PRIMARY_ROUTES,
7
7
  SesameClient,
8
8
  WORKER_ROUTES
9
- } from "./chunk-QAOBO4W4.js";
9
+ } from "./chunk-MKVGEXKO.js";
10
10
 
11
11
  // packages/runtime/src/watchdog.ts
12
12
  import { execSync } from "child_process";
@@ -1048,4 +1048,4 @@ export {
1048
1048
  WorkerMemorySync,
1049
1049
  PrimaryMemorySync
1050
1050
  };
1051
- //# sourceMappingURL=chunk-AGFKYYWT.js.map
1051
+ //# sourceMappingURL=chunk-JV3WKYNF.js.map
@@ -1997,58 +1997,42 @@ var HEALTH_PORT = 9484;
1997
1997
  var HEALTH_PATH = "/health";
1998
1998
 
1999
1999
  // packages/runtime/src/request-logger.ts
2000
- import Database from "better-sqlite3";
2001
2000
  import { randomUUID } from "crypto";
2002
- import { mkdirSync, existsSync as existsSync3 } from "fs";
2001
+ import { mkdirSync, existsSync as existsSync3, appendFileSync, readFileSync as readFileSync4, writeFileSync } from "fs";
2003
2002
  import { dirname as dirname3 } from "path";
2004
2003
  var RequestLogger = class {
2005
- db;
2004
+ logPath;
2005
+ maxAgeDays = 7;
2006
2006
  constructor(dbPath) {
2007
- const dir = dirname3(dbPath);
2007
+ this.logPath = dbPath.replace(/\.db$/, ".jsonl");
2008
+ if (this.logPath === dbPath) this.logPath = dbPath + ".jsonl";
2009
+ const dir = dirname3(this.logPath);
2008
2010
  if (!existsSync3(dir)) mkdirSync(dir, { recursive: true });
2009
- this.db = new Database(dbPath);
2010
- this.db.pragma("journal_mode = WAL");
2011
- this.db.pragma("synchronous = NORMAL");
2012
- this.init();
2013
2011
  this.prune();
2014
2012
  }
2015
- init() {
2016
- this.db.exec(`
2017
- CREATE TABLE IF NOT EXISTS request_logs (
2018
- id TEXT PRIMARY KEY,
2019
- timestamp TEXT NOT NULL,
2020
- context TEXT NOT NULL,
2021
- context_switched INTEGER NOT NULL DEFAULT 0,
2022
- routing_reason TEXT NOT NULL DEFAULT '',
2023
- channel_id TEXT NOT NULL DEFAULT '',
2024
- channel_kind TEXT NOT NULL DEFAULT '',
2025
- sender_handle TEXT NOT NULL DEFAULT '',
2026
- raw_message TEXT NOT NULL,
2027
- system_prompt_components TEXT NOT NULL,
2028
- conversation_history TEXT NOT NULL,
2029
- user_message TEXT NOT NULL,
2030
- response_content TEXT NOT NULL,
2031
- response_model TEXT NOT NULL,
2032
- response_latency_ms INTEGER NOT NULL,
2033
- response_skipped INTEGER NOT NULL DEFAULT 0,
2034
- config_snapshot TEXT NOT NULL,
2035
- token_est_system INTEGER NOT NULL DEFAULT 0,
2036
- token_est_history INTEGER NOT NULL DEFAULT 0,
2037
- token_est_user INTEGER NOT NULL DEFAULT 0,
2038
- token_est_total INTEGER NOT NULL DEFAULT 0
2039
- )
2040
- `);
2041
- this.db.exec(`
2042
- CREATE INDEX IF NOT EXISTS idx_request_logs_timestamp ON request_logs(timestamp DESC);
2043
- CREATE INDEX IF NOT EXISTS idx_request_logs_context ON request_logs(context);
2044
- CREATE INDEX IF NOT EXISTS idx_request_logs_sender ON request_logs(sender_handle);
2045
- `);
2046
- }
2047
2013
  prune() {
2048
- const cutoff = new Date(Date.now() - 7 * 24 * 60 * 60 * 1e3).toISOString();
2049
- const result = this.db.prepare("DELETE FROM request_logs WHERE timestamp < ?").run(cutoff);
2050
- if (result.changes > 0) {
2051
- console.log(`[dashboard] Pruned ${result.changes} old request logs`);
2014
+ if (!existsSync3(this.logPath)) return;
2015
+ const cutoff = new Date(Date.now() - this.maxAgeDays * 24 * 60 * 60 * 1e3).toISOString();
2016
+ try {
2017
+ const lines = readFileSync4(this.logPath, "utf-8").split("\n").filter(Boolean);
2018
+ const kept = [];
2019
+ let pruned = 0;
2020
+ for (const line of lines) {
2021
+ try {
2022
+ const entry = JSON.parse(line);
2023
+ if (entry.timestamp >= cutoff) {
2024
+ kept.push(line);
2025
+ } else {
2026
+ pruned++;
2027
+ }
2028
+ } catch {
2029
+ }
2030
+ }
2031
+ if (pruned > 0) {
2032
+ writeFileSync(this.logPath, kept.join("\n") + (kept.length > 0 ? "\n" : ""));
2033
+ console.log(`[dashboard] Pruned ${pruned} old request logs`);
2034
+ }
2035
+ } catch {
2052
2036
  }
2053
2037
  }
2054
2038
  log(entry) {
@@ -2059,78 +2043,73 @@ var RequestLogger = class {
2059
2043
  entry.conversationHistory.reduce((sum, m) => sum + m.content.length, 0) / 4
2060
2044
  );
2061
2045
  const userTokens = Math.ceil(entry.userMessage.length / 4);
2062
- this.db.prepare(
2063
- `INSERT INTO request_logs (
2064
- id, timestamp, context, context_switched, routing_reason,
2065
- channel_id, channel_kind, sender_handle, raw_message,
2066
- system_prompt_components, conversation_history, user_message,
2067
- response_content, response_model, response_latency_ms, response_skipped,
2068
- config_snapshot,
2069
- token_est_system, token_est_history, token_est_user, token_est_total
2070
- ) VALUES (
2071
- ?, ?, ?, ?, ?,
2072
- ?, ?, ?, ?,
2073
- ?, ?, ?,
2074
- ?, ?, ?, ?,
2075
- ?,
2076
- ?, ?, ?, ?
2077
- )`
2078
- ).run(
2046
+ const record = {
2079
2047
  id,
2080
2048
  timestamp,
2081
- entry.context,
2082
- entry.contextSwitched ? 1 : 0,
2083
- entry.routingReason,
2084
- entry.channelId ?? "",
2085
- entry.channelKind ?? "",
2086
- entry.senderHandle ?? "",
2087
- entry.rawMessage,
2088
- JSON.stringify(entry.systemPromptComponents),
2089
- JSON.stringify(entry.conversationHistory),
2090
- entry.userMessage,
2091
- entry.response.content,
2092
- entry.response.model,
2093
- entry.response.latencyMs,
2094
- entry.response.skipped ? 1 : 0,
2095
- JSON.stringify(entry.config),
2096
- sysTokens,
2097
- histTokens,
2098
- userTokens,
2099
- sysTokens + histTokens + userTokens
2100
- );
2049
+ context: entry.context,
2050
+ context_switched: entry.contextSwitched,
2051
+ routing_reason: entry.routingReason,
2052
+ channel_id: entry.channelId ?? "",
2053
+ channel_kind: entry.channelKind ?? "",
2054
+ sender_handle: entry.senderHandle ?? "",
2055
+ raw_message: entry.rawMessage,
2056
+ system_prompt_components: JSON.stringify(entry.systemPromptComponents),
2057
+ conversation_history: JSON.stringify(entry.conversationHistory),
2058
+ user_message: entry.userMessage,
2059
+ response_content: entry.response.content,
2060
+ response_model: entry.response.model,
2061
+ response_latency_ms: entry.response.latencyMs,
2062
+ response_skipped: entry.response.skipped,
2063
+ config_snapshot: JSON.stringify(entry.config),
2064
+ token_est_system: sysTokens,
2065
+ token_est_history: histTokens,
2066
+ token_est_user: userTokens,
2067
+ token_est_total: sysTokens + histTokens + userTokens
2068
+ };
2069
+ appendFileSync(this.logPath, JSON.stringify(record) + "\n");
2101
2070
  return id;
2102
2071
  }
2103
2072
  getRequests(opts = {}) {
2104
2073
  const limit = opts.limit ?? 50;
2105
2074
  const offset = opts.offset ?? 0;
2106
- const conditions = [];
2107
- const params = [];
2075
+ let entries = this.readAll();
2108
2076
  if (opts.context) {
2109
- conditions.push("context = ?");
2110
- params.push(opts.context);
2077
+ entries = entries.filter((e) => e.context === opts.context);
2111
2078
  }
2112
2079
  if (opts.sender) {
2113
- conditions.push("sender_handle = ?");
2114
- params.push(opts.sender);
2115
- }
2116
- const where = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
2117
- const total = this.db.prepare(`SELECT COUNT(*) as count FROM request_logs ${where}`).get(...params).count;
2118
- const requests = this.db.prepare(
2119
- `SELECT * FROM request_logs ${where} ORDER BY timestamp DESC LIMIT ? OFFSET ?`
2120
- ).all(...params, limit, offset);
2080
+ entries = entries.filter((e) => e.sender_handle === opts.sender);
2081
+ }
2082
+ entries.sort((a, b) => b.timestamp.localeCompare(a.timestamp));
2083
+ const total = entries.length;
2084
+ const requests = entries.slice(offset, offset + limit);
2121
2085
  return { requests, total };
2122
2086
  }
2123
2087
  getRequest(id) {
2124
- return this.db.prepare("SELECT * FROM request_logs WHERE id = ?").get(id);
2088
+ return this.readAll().find((e) => e.id === id);
2125
2089
  }
2126
2090
  close() {
2127
- this.db.close();
2091
+ }
2092
+ readAll() {
2093
+ if (!existsSync3(this.logPath)) return [];
2094
+ try {
2095
+ const lines = readFileSync4(this.logPath, "utf-8").split("\n").filter(Boolean);
2096
+ const entries = [];
2097
+ for (const line of lines) {
2098
+ try {
2099
+ entries.push(JSON.parse(line));
2100
+ } catch {
2101
+ }
2102
+ }
2103
+ return entries;
2104
+ } catch {
2105
+ return [];
2106
+ }
2128
2107
  }
2129
2108
  };
2130
2109
 
2131
2110
  // packages/runtime/src/dashboard.ts
2132
2111
  import { createServer } from "http";
2133
- import { readFileSync as readFileSync4 } from "fs";
2112
+ import { readFileSync as readFileSync5 } from "fs";
2134
2113
  import { resolve as resolve4, dirname as dirname4 } from "path";
2135
2114
  import { fileURLToPath as fileURLToPath2 } from "url";
2136
2115
  var __dirname = dirname4(fileURLToPath2(import.meta.url));
@@ -2140,7 +2119,7 @@ function getSpaHtml() {
2140
2119
  if (!spaHtml) {
2141
2120
  for (const dir of [__dirname, resolve4(__dirname, "../src")]) {
2142
2121
  try {
2143
- spaHtml = readFileSync4(resolve4(dir, "dashboard.html"), "utf-8");
2122
+ spaHtml = readFileSync5(resolve4(dir, "dashboard.html"), "utf-8");
2144
2123
  break;
2145
2124
  } catch {
2146
2125
  }
@@ -2262,13 +2241,13 @@ function startDashboardServer(requestLogger, memoryConfig) {
2262
2241
  }
2263
2242
 
2264
2243
  // packages/runtime/src/pipeline.ts
2265
- import { readFileSync as readFileSync5, writeFileSync, unlinkSync } from "fs";
2244
+ import { readFileSync as readFileSync6, writeFileSync as writeFileSync2, unlinkSync } from "fs";
2266
2245
  import { resolve as resolve5, dirname as dirname5 } from "path";
2267
2246
  import { fileURLToPath as fileURLToPath3 } from "url";
2268
2247
  var PACKAGE_VERSION = "unknown";
2269
2248
  try {
2270
2249
  const __dirname2 = dirname5(fileURLToPath3(import.meta.url));
2271
- const pkg = JSON.parse(readFileSync5(resolve5(__dirname2, "../package.json"), "utf-8"));
2250
+ const pkg = JSON.parse(readFileSync6(resolve5(__dirname2, "../package.json"), "utf-8"));
2272
2251
  PACKAGE_VERSION = pkg.version ?? "unknown";
2273
2252
  } catch {
2274
2253
  }
@@ -2299,7 +2278,7 @@ function startHealthServer(port) {
2299
2278
  return server;
2300
2279
  }
2301
2280
  function writePidFile(path) {
2302
- writeFileSync(path, String(process.pid));
2281
+ writeFileSync2(path, String(process.pid));
2303
2282
  console.log(`[hivemind] PID file written: ${path}`);
2304
2283
  }
2305
2284
  function cleanupPidFile(path) {
@@ -2944,4 +2923,4 @@ smol-toml/dist/index.js:
2944
2923
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2945
2924
  *)
2946
2925
  */
2947
- //# sourceMappingURL=chunk-QAOBO4W4.js.map
2926
+ //# sourceMappingURL=chunk-MKVGEXKO.js.map