@kenhkl/agent-gate 0.5.2 → 0.5.3

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/cli.js CHANGED
@@ -50,7 +50,7 @@ var init_version = __esm({
50
50
  "src/version.ts"() {
51
51
  "use strict";
52
52
  init_cjs_shims();
53
- _version = true ? "0.5.2" : (() => {
53
+ _version = true ? "0.5.3" : (() => {
54
54
  try {
55
55
  const require2 = createRequire(importMetaUrl);
56
56
  const pkg = require2("../package.json");
@@ -232,6 +232,22 @@ var init_json_storage = __esm({
232
232
  const limit = params.limit || 50;
233
233
  return allRecords.slice(offset, offset + limit);
234
234
  }
235
+ countToolCalls(params) {
236
+ const sessions = this.loadSessions();
237
+ let allRecords = [];
238
+ try {
239
+ const files = (0, import_fs.readdirSync)(this.toolCallsDir).filter((f) => f.endsWith(".json"));
240
+ for (const file of files) {
241
+ const records = this.readJsonFile((0, import_path.join)(this.toolCallsDir, file), []);
242
+ allRecords.push(...records);
243
+ }
244
+ } catch {
245
+ }
246
+ if (params.decision) {
247
+ allRecords = allRecords.filter((r) => r.decision === params.decision);
248
+ }
249
+ return allRecords.length;
250
+ }
235
251
  enrichRecord(record, sessions, agents) {
236
252
  const session = sessions.get(record.session_id);
237
253
  const agentId = session?.agent_id;
@@ -458,6 +474,19 @@ CREATE INDEX IF NOT EXISTS idx_tool_calls_decision ON tool_calls(decision, calle
458
474
  ${where} ORDER BY tc.called_at DESC LIMIT ? OFFSET ?`
459
475
  ).all(...values, limit, offset);
460
476
  }
477
+ countToolCalls(params) {
478
+ const conditions = [];
479
+ const values = [];
480
+ if (params.decision) {
481
+ conditions.push("tc.decision = ?");
482
+ values.push(params.decision);
483
+ }
484
+ const where = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
485
+ const row = this.db.prepare(
486
+ `SELECT COUNT(*) as total FROM tool_calls tc ${where}`
487
+ ).get(...values);
488
+ return row?.total ?? 0;
489
+ }
461
490
  getAgentsList() {
462
491
  return this.db.prepare(`
463
492
  SELECT a.agent_type, a.hostname, a.agent_version as version,
@@ -868,6 +897,9 @@ function insertToolCall(record) {
868
897
  function queryToolCalls(params) {
869
898
  return store().queryToolCalls(params);
870
899
  }
900
+ function countToolCalls(params) {
901
+ return store().countToolCalls(params);
902
+ }
871
903
  function getAgentsList() {
872
904
  return store().getAgentsList();
873
905
  }
@@ -964,8 +996,9 @@ async function toolCallsRoute(c) {
964
996
  const decision = c.req.query("decision");
965
997
  const limit = parseInt(c.req.query("limit") || "50", 10);
966
998
  const offset = parseInt(c.req.query("offset") || "0", 10);
967
- const rows = queryToolCalls({ decision, limit, offset });
968
- return c.json(rows);
999
+ const total = countToolCalls({ decision });
1000
+ const data = queryToolCalls({ decision, limit, offset });
1001
+ return c.json({ total, data });
969
1002
  }
970
1003
  async function agentsRoute(c) {
971
1004
  const agents = getAgentsList();