@kenhkl/agent-gate 0.5.2 → 0.5.4

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.4" : (() => {
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,
@@ -584,11 +613,11 @@ function setMossUrl(url) {
584
613
  }
585
614
  async function callAgentMoss(request) {
586
615
  try {
587
- const resp = await fetch(`${mossUrl}/api/v1/analyze`, {
616
+ const resp = await (0, import_node_fetch.default)(`${mossUrl}/api/v1/analyze`, {
588
617
  method: "POST",
589
618
  headers: { "Content-Type": "application/json" },
590
619
  body: JSON.stringify(request),
591
- signal: AbortSignal.timeout(3e4)
620
+ timeout: 3e4
592
621
  });
593
622
  if (!resp.ok) {
594
623
  console.error(`[AgentGate] AgentMoss HTTP ${resp.status}: ${resp.statusText}`);
@@ -602,8 +631,8 @@ async function callAgentMoss(request) {
602
631
  }
603
632
  async function fetchMossHealth() {
604
633
  try {
605
- const resp = await fetch(`${mossUrl}/api/v1/health`, {
606
- signal: AbortSignal.timeout(3e3)
634
+ const resp = await (0, import_node_fetch.default)(`${mossUrl}/api/v1/health`, {
635
+ timeout: 3e3
607
636
  });
608
637
  if (!resp.ok) {
609
638
  return { moss_version: "N/A", moss_status: "error" };
@@ -627,11 +656,12 @@ function failClosedResponse(reason) {
627
656
  confidence: 100
628
657
  };
629
658
  }
630
- var DEFAULT_MOSS_URL, mossUrl;
659
+ var import_node_fetch, DEFAULT_MOSS_URL, mossUrl;
631
660
  var init_moss_client = __esm({
632
661
  "src/shared/moss-client.ts"() {
633
662
  "use strict";
634
663
  init_cjs_shims();
664
+ import_node_fetch = __toESM(require("node-fetch"));
635
665
  DEFAULT_MOSS_URL = "http://127.0.0.1:9090";
636
666
  mossUrl = DEFAULT_MOSS_URL;
637
667
  }
@@ -868,6 +898,9 @@ function insertToolCall(record) {
868
898
  function queryToolCalls(params) {
869
899
  return store().queryToolCalls(params);
870
900
  }
901
+ function countToolCalls(params) {
902
+ return store().countToolCalls(params);
903
+ }
871
904
  function getAgentsList() {
872
905
  return store().getAgentsList();
873
906
  }
@@ -964,8 +997,9 @@ async function toolCallsRoute(c) {
964
997
  const decision = c.req.query("decision");
965
998
  const limit = parseInt(c.req.query("limit") || "50", 10);
966
999
  const offset = parseInt(c.req.query("offset") || "0", 10);
967
- const rows = queryToolCalls({ decision, limit, offset });
968
- return c.json(rows);
1000
+ const total = countToolCalls({ decision });
1001
+ const data = queryToolCalls({ decision, limit, offset });
1002
+ return c.json({ total, data });
969
1003
  }
970
1004
  async function agentsRoute(c) {
971
1005
  const agents = getAgentsList();
@@ -29401,6 +29435,7 @@ init_cjs_shims();
29401
29435
  var import_node_fs4 = require("fs");
29402
29436
  var import_yaml3 = require("yaml");
29403
29437
  init_version();
29438
+ var import_node_fetch2 = __toESM(require("node-fetch"));
29404
29439
  async function main() {
29405
29440
  const args = process.argv.slice(2);
29406
29441
  const command = args[0];
@@ -29802,7 +29837,7 @@ Run options:
29802
29837
  const mossUrl2 = process.env.AGENT_MOSS_URL || "http://127.0.0.1:9090";
29803
29838
  let mossConnected = false;
29804
29839
  try {
29805
- const resp = await fetch(`${mossUrl2}/api/v1/health`, { signal: AbortSignal.timeout(3e3) });
29840
+ const resp = await (0, import_node_fetch2.default)(`${mossUrl2}/api/v1/health`, { timeout: 3e3 });
29806
29841
  if (resp.status === 200) {
29807
29842
  mossConnected = true;
29808
29843
  console.log(`[AgentGate] AgentMoss connected: ${mossUrl2}`);