@kenhkl/agent-gate 0.8.2 → 0.9.0
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/config/trigger_rules.yaml +585 -0
- package/dist/shared/storage/db.d.ts +19 -9
- package/dist/shared/storage/db.js +69 -3
- package/dist/v1/cli.js +98 -15
- package/dist/v1/server.js +98 -15
- package/dist/v3/cli.js +274 -145
- package/package.json +1 -1
|
@@ -271,9 +271,21 @@ var init_json_storage = __esm({
|
|
|
271
271
|
if (params.agentType) {
|
|
272
272
|
allRecords = allRecords.filter((r) => r.agent_type === params.agentType);
|
|
273
273
|
}
|
|
274
|
+
if (params.agentId) {
|
|
275
|
+
allRecords = allRecords.filter((r) => `${r.agent_type}:${r.hostname}` === params.agentId);
|
|
276
|
+
}
|
|
274
277
|
if (params.decision) {
|
|
275
278
|
allRecords = allRecords.filter((r) => r.decision === params.decision);
|
|
276
279
|
}
|
|
280
|
+
if (params.riskLevel) {
|
|
281
|
+
allRecords = allRecords.filter((r) => r.risk_level === params.riskLevel);
|
|
282
|
+
}
|
|
283
|
+
if (params.fromTime) {
|
|
284
|
+
allRecords = allRecords.filter((r) => r.called_at >= params.fromTime);
|
|
285
|
+
}
|
|
286
|
+
if (params.toTime) {
|
|
287
|
+
allRecords = allRecords.filter((r) => r.called_at <= params.toTime);
|
|
288
|
+
}
|
|
277
289
|
allRecords.sort((a, b) => b.called_at.localeCompare(a.called_at));
|
|
278
290
|
const offset = params.offset || 0;
|
|
279
291
|
const limit = params.limit || 50;
|
|
@@ -291,6 +303,15 @@ var init_json_storage = __esm({
|
|
|
291
303
|
}
|
|
292
304
|
} catch {
|
|
293
305
|
}
|
|
306
|
+
if (params.sessionId) {
|
|
307
|
+
allRecords = allRecords.filter((r) => r.session_id === params.sessionId);
|
|
308
|
+
}
|
|
309
|
+
if (params.agentId) {
|
|
310
|
+
const allowed = new Set(
|
|
311
|
+
[...sessions.values()].filter((s) => s.agent_id === params.agentId).map((s) => s.id)
|
|
312
|
+
);
|
|
313
|
+
allRecords = allRecords.filter((r) => allowed.has(r.session_id));
|
|
314
|
+
}
|
|
294
315
|
if (params.agentType) {
|
|
295
316
|
const allowed = new Set(
|
|
296
317
|
[...sessions.values()].filter((s) => (agents.get(s.agent_id)?.agent_type || "") === params.agentType).map((s) => s.id)
|
|
@@ -300,6 +321,15 @@ var init_json_storage = __esm({
|
|
|
300
321
|
if (params.decision) {
|
|
301
322
|
allRecords = allRecords.filter((r) => r.decision === params.decision);
|
|
302
323
|
}
|
|
324
|
+
if (params.riskLevel) {
|
|
325
|
+
allRecords = allRecords.filter((r) => r.risk_level === params.riskLevel);
|
|
326
|
+
}
|
|
327
|
+
if (params.fromTime) {
|
|
328
|
+
allRecords = allRecords.filter((r) => r.called_at >= params.fromTime);
|
|
329
|
+
}
|
|
330
|
+
if (params.toTime) {
|
|
331
|
+
allRecords = allRecords.filter((r) => r.called_at <= params.toTime);
|
|
332
|
+
}
|
|
303
333
|
return allRecords.length;
|
|
304
334
|
}
|
|
305
335
|
getStorageStats() {
|
|
@@ -556,6 +586,10 @@ CREATE INDEX IF NOT EXISTS idx_tool_calls_decision ON tool_calls(decision, calle
|
|
|
556
586
|
conditions.push("tc.session_id = ?");
|
|
557
587
|
values.push(params.sessionId);
|
|
558
588
|
}
|
|
589
|
+
if (params.agentId) {
|
|
590
|
+
conditions.push("s.agent_id = ?");
|
|
591
|
+
values.push(params.agentId);
|
|
592
|
+
}
|
|
559
593
|
if (params.agentType) {
|
|
560
594
|
conditions.push("a.agent_type = ?");
|
|
561
595
|
values.push(params.agentType);
|
|
@@ -564,6 +598,18 @@ CREATE INDEX IF NOT EXISTS idx_tool_calls_decision ON tool_calls(decision, calle
|
|
|
564
598
|
conditions.push("tc.decision = ?");
|
|
565
599
|
values.push(params.decision);
|
|
566
600
|
}
|
|
601
|
+
if (params.riskLevel) {
|
|
602
|
+
conditions.push("tc.risk_level = ?");
|
|
603
|
+
values.push(params.riskLevel);
|
|
604
|
+
}
|
|
605
|
+
if (params.fromTime) {
|
|
606
|
+
conditions.push("tc.called_at >= ?");
|
|
607
|
+
values.push(params.fromTime);
|
|
608
|
+
}
|
|
609
|
+
if (params.toTime) {
|
|
610
|
+
conditions.push("tc.called_at <= ?");
|
|
611
|
+
values.push(params.toTime);
|
|
612
|
+
}
|
|
567
613
|
const where = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
568
614
|
const limit = params.limit || 50;
|
|
569
615
|
const offset = params.offset || 0;
|
|
@@ -578,14 +624,34 @@ CREATE INDEX IF NOT EXISTS idx_tool_calls_decision ON tool_calls(decision, calle
|
|
|
578
624
|
countToolCalls(params) {
|
|
579
625
|
const conditions = [];
|
|
580
626
|
const values = [];
|
|
581
|
-
if (params.
|
|
582
|
-
conditions.push("tc.
|
|
583
|
-
values.push(params.
|
|
627
|
+
if (params.sessionId) {
|
|
628
|
+
conditions.push("tc.session_id = ?");
|
|
629
|
+
values.push(params.sessionId);
|
|
630
|
+
}
|
|
631
|
+
if (params.agentId) {
|
|
632
|
+
conditions.push("s.agent_id = ?");
|
|
633
|
+
values.push(params.agentId);
|
|
584
634
|
}
|
|
585
635
|
if (params.agentType) {
|
|
586
636
|
conditions.push("a.agent_type = ?");
|
|
587
637
|
values.push(params.agentType);
|
|
588
638
|
}
|
|
639
|
+
if (params.decision) {
|
|
640
|
+
conditions.push("tc.decision = ?");
|
|
641
|
+
values.push(params.decision);
|
|
642
|
+
}
|
|
643
|
+
if (params.riskLevel) {
|
|
644
|
+
conditions.push("tc.risk_level = ?");
|
|
645
|
+
values.push(params.riskLevel);
|
|
646
|
+
}
|
|
647
|
+
if (params.fromTime) {
|
|
648
|
+
conditions.push("tc.called_at >= ?");
|
|
649
|
+
values.push(params.fromTime);
|
|
650
|
+
}
|
|
651
|
+
if (params.toTime) {
|
|
652
|
+
conditions.push("tc.called_at <= ?");
|
|
653
|
+
values.push(params.toTime);
|
|
654
|
+
}
|
|
589
655
|
const where = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
590
656
|
const row = this.db.prepare(
|
|
591
657
|
`SELECT COUNT(*) as total FROM tool_calls tc
|
package/dist/v1/cli.js
CHANGED
|
@@ -795,9 +795,21 @@ var init_json_storage = __esm({
|
|
|
795
795
|
if (params.agentType) {
|
|
796
796
|
allRecords = allRecords.filter((r) => r.agent_type === params.agentType);
|
|
797
797
|
}
|
|
798
|
+
if (params.agentId) {
|
|
799
|
+
allRecords = allRecords.filter((r) => `${r.agent_type}:${r.hostname}` === params.agentId);
|
|
800
|
+
}
|
|
798
801
|
if (params.decision) {
|
|
799
802
|
allRecords = allRecords.filter((r) => r.decision === params.decision);
|
|
800
803
|
}
|
|
804
|
+
if (params.riskLevel) {
|
|
805
|
+
allRecords = allRecords.filter((r) => r.risk_level === params.riskLevel);
|
|
806
|
+
}
|
|
807
|
+
if (params.fromTime) {
|
|
808
|
+
allRecords = allRecords.filter((r) => r.called_at >= params.fromTime);
|
|
809
|
+
}
|
|
810
|
+
if (params.toTime) {
|
|
811
|
+
allRecords = allRecords.filter((r) => r.called_at <= params.toTime);
|
|
812
|
+
}
|
|
801
813
|
allRecords.sort((a, b) => b.called_at.localeCompare(a.called_at));
|
|
802
814
|
const offset = params.offset || 0;
|
|
803
815
|
const limit = params.limit || 50;
|
|
@@ -815,6 +827,15 @@ var init_json_storage = __esm({
|
|
|
815
827
|
}
|
|
816
828
|
} catch {
|
|
817
829
|
}
|
|
830
|
+
if (params.sessionId) {
|
|
831
|
+
allRecords = allRecords.filter((r) => r.session_id === params.sessionId);
|
|
832
|
+
}
|
|
833
|
+
if (params.agentId) {
|
|
834
|
+
const allowed = new Set(
|
|
835
|
+
[...sessions.values()].filter((s) => s.agent_id === params.agentId).map((s) => s.id)
|
|
836
|
+
);
|
|
837
|
+
allRecords = allRecords.filter((r) => allowed.has(r.session_id));
|
|
838
|
+
}
|
|
818
839
|
if (params.agentType) {
|
|
819
840
|
const allowed = new Set(
|
|
820
841
|
[...sessions.values()].filter((s) => (agents.get(s.agent_id)?.agent_type || "") === params.agentType).map((s) => s.id)
|
|
@@ -824,6 +845,15 @@ var init_json_storage = __esm({
|
|
|
824
845
|
if (params.decision) {
|
|
825
846
|
allRecords = allRecords.filter((r) => r.decision === params.decision);
|
|
826
847
|
}
|
|
848
|
+
if (params.riskLevel) {
|
|
849
|
+
allRecords = allRecords.filter((r) => r.risk_level === params.riskLevel);
|
|
850
|
+
}
|
|
851
|
+
if (params.fromTime) {
|
|
852
|
+
allRecords = allRecords.filter((r) => r.called_at >= params.fromTime);
|
|
853
|
+
}
|
|
854
|
+
if (params.toTime) {
|
|
855
|
+
allRecords = allRecords.filter((r) => r.called_at <= params.toTime);
|
|
856
|
+
}
|
|
827
857
|
return allRecords.length;
|
|
828
858
|
}
|
|
829
859
|
getStorageStats() {
|
|
@@ -1080,6 +1110,10 @@ CREATE INDEX IF NOT EXISTS idx_tool_calls_decision ON tool_calls(decision, calle
|
|
|
1080
1110
|
conditions.push("tc.session_id = ?");
|
|
1081
1111
|
values.push(params.sessionId);
|
|
1082
1112
|
}
|
|
1113
|
+
if (params.agentId) {
|
|
1114
|
+
conditions.push("s.agent_id = ?");
|
|
1115
|
+
values.push(params.agentId);
|
|
1116
|
+
}
|
|
1083
1117
|
if (params.agentType) {
|
|
1084
1118
|
conditions.push("a.agent_type = ?");
|
|
1085
1119
|
values.push(params.agentType);
|
|
@@ -1088,6 +1122,18 @@ CREATE INDEX IF NOT EXISTS idx_tool_calls_decision ON tool_calls(decision, calle
|
|
|
1088
1122
|
conditions.push("tc.decision = ?");
|
|
1089
1123
|
values.push(params.decision);
|
|
1090
1124
|
}
|
|
1125
|
+
if (params.riskLevel) {
|
|
1126
|
+
conditions.push("tc.risk_level = ?");
|
|
1127
|
+
values.push(params.riskLevel);
|
|
1128
|
+
}
|
|
1129
|
+
if (params.fromTime) {
|
|
1130
|
+
conditions.push("tc.called_at >= ?");
|
|
1131
|
+
values.push(params.fromTime);
|
|
1132
|
+
}
|
|
1133
|
+
if (params.toTime) {
|
|
1134
|
+
conditions.push("tc.called_at <= ?");
|
|
1135
|
+
values.push(params.toTime);
|
|
1136
|
+
}
|
|
1091
1137
|
const where = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
1092
1138
|
const limit = params.limit || 50;
|
|
1093
1139
|
const offset = params.offset || 0;
|
|
@@ -1102,14 +1148,34 @@ CREATE INDEX IF NOT EXISTS idx_tool_calls_decision ON tool_calls(decision, calle
|
|
|
1102
1148
|
countToolCalls(params) {
|
|
1103
1149
|
const conditions = [];
|
|
1104
1150
|
const values = [];
|
|
1105
|
-
if (params.
|
|
1106
|
-
conditions.push("tc.
|
|
1107
|
-
values.push(params.
|
|
1151
|
+
if (params.sessionId) {
|
|
1152
|
+
conditions.push("tc.session_id = ?");
|
|
1153
|
+
values.push(params.sessionId);
|
|
1154
|
+
}
|
|
1155
|
+
if (params.agentId) {
|
|
1156
|
+
conditions.push("s.agent_id = ?");
|
|
1157
|
+
values.push(params.agentId);
|
|
1108
1158
|
}
|
|
1109
1159
|
if (params.agentType) {
|
|
1110
1160
|
conditions.push("a.agent_type = ?");
|
|
1111
1161
|
values.push(params.agentType);
|
|
1112
1162
|
}
|
|
1163
|
+
if (params.decision) {
|
|
1164
|
+
conditions.push("tc.decision = ?");
|
|
1165
|
+
values.push(params.decision);
|
|
1166
|
+
}
|
|
1167
|
+
if (params.riskLevel) {
|
|
1168
|
+
conditions.push("tc.risk_level = ?");
|
|
1169
|
+
values.push(params.riskLevel);
|
|
1170
|
+
}
|
|
1171
|
+
if (params.fromTime) {
|
|
1172
|
+
conditions.push("tc.called_at >= ?");
|
|
1173
|
+
values.push(params.fromTime);
|
|
1174
|
+
}
|
|
1175
|
+
if (params.toTime) {
|
|
1176
|
+
conditions.push("tc.called_at <= ?");
|
|
1177
|
+
values.push(params.toTime);
|
|
1178
|
+
}
|
|
1113
1179
|
const where = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
1114
1180
|
const row = this.db.prepare(
|
|
1115
1181
|
`SELECT COUNT(*) as total FROM tool_calls tc
|
|
@@ -1453,7 +1519,7 @@ var init_version = __esm({
|
|
|
1453
1519
|
"src/version.ts"() {
|
|
1454
1520
|
"use strict";
|
|
1455
1521
|
init_cjs_shims();
|
|
1456
|
-
_version = true ? "0.
|
|
1522
|
+
_version = true ? "0.9.0" : (() => {
|
|
1457
1523
|
try {
|
|
1458
1524
|
const require2 = createRequire(importMetaUrl);
|
|
1459
1525
|
const pkg = require2("../package.json");
|
|
@@ -1491,18 +1557,23 @@ var init_models = __esm({
|
|
|
1491
1557
|
text: import_zod.z.string().default(""),
|
|
1492
1558
|
actions: import_zod.z.array(import_zod.z.object({
|
|
1493
1559
|
action_type: import_zod.z.string(),
|
|
1494
|
-
action_detail: import_zod.z.string()
|
|
1560
|
+
action_detail: import_zod.z.string(),
|
|
1561
|
+
output: import_zod.z.string().optional().describe("\u5DE5\u5177\u8FD4\u56DE\u5185\u5BB9\uFF1Bask_user_question \u7684\u7528\u6237\u56DE\u7B54\u9760\u5B83\u4F20\u7ED9 AgentMoss \u5224\u6388\u6743")
|
|
1495
1562
|
})).default([])
|
|
1496
1563
|
})).default([]),
|
|
1497
1564
|
action_history: import_zod.z.array(import_zod.z.object({
|
|
1498
1565
|
action_type: import_zod.z.string(),
|
|
1499
|
-
action_detail: import_zod.z.string()
|
|
1566
|
+
action_detail: import_zod.z.string(),
|
|
1567
|
+
// 授权类规则(改密码 / 删用户)靠 ask_user_question 的 output 判断用户是否已确认。
|
|
1568
|
+
// 此前 schema 里没有这个字段,Agent 传了也会被剥掉 → 必然判成「未授权」。
|
|
1569
|
+
output: import_zod.z.string().optional().describe("\u5DE5\u5177\u8FD4\u56DE\u5185\u5BB9\uFF1Bask_user_question \u7684\u7528\u6237\u56DE\u7B54\u9760\u5B83\u4F20\u7ED9 AgentMoss \u5224\u6388\u6743")
|
|
1500
1570
|
})).default([]),
|
|
1501
1571
|
session_history: import_zod.z.array(import_zod.z.object({
|
|
1502
1572
|
session_id: import_zod.z.string(),
|
|
1503
1573
|
action_history: import_zod.z.array(import_zod.z.object({
|
|
1504
1574
|
action_type: import_zod.z.string(),
|
|
1505
|
-
action_detail: import_zod.z.string()
|
|
1575
|
+
action_detail: import_zod.z.string(),
|
|
1576
|
+
output: import_zod.z.string().optional()
|
|
1506
1577
|
})).default([])
|
|
1507
1578
|
})).default([]).describe("\u591A session \u5386\u53F2\u52A8\u4F5C\uFF08\u53EF\u9009\uFF09\uFF1A\u4F9B AgentMoss L2.4 \u5F62\u5F0F\u5316\u5F15\u64CE\u8DE8\u4F1A\u8BDD\u9A8C\u8BC1"),
|
|
1508
1579
|
metadata: import_zod.z.record(import_zod.z.unknown()).optional()
|
|
@@ -1547,20 +1618,23 @@ var init_models = __esm({
|
|
|
1547
1618
|
function normalize(input, systemContext) {
|
|
1548
1619
|
const actionHistory = input.action_history.map((h) => ({
|
|
1549
1620
|
action_type: h.action_type,
|
|
1550
|
-
action_detail: h.action_detail
|
|
1621
|
+
action_detail: h.action_detail,
|
|
1622
|
+
output: h.output ?? ""
|
|
1551
1623
|
}));
|
|
1552
1624
|
const sessionHistory = (input.session_history || []).map((s) => ({
|
|
1553
1625
|
session_id: s.session_id,
|
|
1554
1626
|
action_history: s.action_history.map((h) => ({
|
|
1555
1627
|
action_type: h.action_type,
|
|
1556
|
-
action_detail: h.action_detail
|
|
1628
|
+
action_detail: h.action_detail,
|
|
1629
|
+
output: h.output ?? ""
|
|
1557
1630
|
}))
|
|
1558
1631
|
}));
|
|
1559
1632
|
const promptHistory = input.prompt_history.map((t) => ({
|
|
1560
1633
|
text: t.text,
|
|
1561
1634
|
actions: t.actions.map((a) => ({
|
|
1562
1635
|
action_type: a.action_type,
|
|
1563
|
-
action_detail: a.action_detail
|
|
1636
|
+
action_detail: a.action_detail,
|
|
1637
|
+
output: a.output ?? ""
|
|
1564
1638
|
}))
|
|
1565
1639
|
}));
|
|
1566
1640
|
const toolName = input.tool_name || input.a_next?.action_type || "unknown";
|
|
@@ -1912,13 +1986,22 @@ async function sessionsRoute(c) {
|
|
|
1912
1986
|
return c.json({ session_id: sessionId, tool_calls: rows });
|
|
1913
1987
|
}
|
|
1914
1988
|
async function toolCallsRoute(c) {
|
|
1915
|
-
const
|
|
1916
|
-
|
|
1917
|
-
const
|
|
1989
|
+
const sessionId = c.req.query("session_id") || void 0;
|
|
1990
|
+
let agentId = c.req.query("agent_id") || void 0;
|
|
1991
|
+
const decision = c.req.query("decision") || void 0;
|
|
1992
|
+
const riskLevel = c.req.query("risk_level") || void 0;
|
|
1993
|
+
const fromTime = c.req.query("from") || void 0;
|
|
1994
|
+
const toTime = c.req.query("to") || void 0;
|
|
1995
|
+
const rawLimit = parseInt(c.req.query("limit") || "50", 10);
|
|
1996
|
+
const limit = Number.isFinite(rawLimit) ? Math.min(Math.max(rawLimit, 1), 500) : 50;
|
|
1997
|
+
const rawOffset = parseInt(c.req.query("offset") || "0", 10);
|
|
1998
|
+
const offset = Number.isFinite(rawOffset) && rawOffset > 0 ? rawOffset : 0;
|
|
1918
1999
|
const bound = boundAgentOf(c.get("principal") || "");
|
|
2000
|
+
if (bound) agentId = void 0;
|
|
1919
2001
|
const agentType = bound || void 0;
|
|
1920
|
-
const
|
|
1921
|
-
const
|
|
2002
|
+
const filter = { sessionId, agentId, agentType, decision, riskLevel, fromTime, toTime };
|
|
2003
|
+
const total = countToolCalls(filter);
|
|
2004
|
+
const data = queryToolCalls({ ...filter, limit, offset });
|
|
1922
2005
|
return c.json({ total, data });
|
|
1923
2006
|
}
|
|
1924
2007
|
async function agentsRoute(c) {
|
package/dist/v1/server.js
CHANGED
|
@@ -836,9 +836,21 @@ var init_json_storage = __esm({
|
|
|
836
836
|
if (params.agentType) {
|
|
837
837
|
allRecords = allRecords.filter((r) => r.agent_type === params.agentType);
|
|
838
838
|
}
|
|
839
|
+
if (params.agentId) {
|
|
840
|
+
allRecords = allRecords.filter((r) => `${r.agent_type}:${r.hostname}` === params.agentId);
|
|
841
|
+
}
|
|
839
842
|
if (params.decision) {
|
|
840
843
|
allRecords = allRecords.filter((r) => r.decision === params.decision);
|
|
841
844
|
}
|
|
845
|
+
if (params.riskLevel) {
|
|
846
|
+
allRecords = allRecords.filter((r) => r.risk_level === params.riskLevel);
|
|
847
|
+
}
|
|
848
|
+
if (params.fromTime) {
|
|
849
|
+
allRecords = allRecords.filter((r) => r.called_at >= params.fromTime);
|
|
850
|
+
}
|
|
851
|
+
if (params.toTime) {
|
|
852
|
+
allRecords = allRecords.filter((r) => r.called_at <= params.toTime);
|
|
853
|
+
}
|
|
842
854
|
allRecords.sort((a, b) => b.called_at.localeCompare(a.called_at));
|
|
843
855
|
const offset = params.offset || 0;
|
|
844
856
|
const limit = params.limit || 50;
|
|
@@ -856,6 +868,15 @@ var init_json_storage = __esm({
|
|
|
856
868
|
}
|
|
857
869
|
} catch {
|
|
858
870
|
}
|
|
871
|
+
if (params.sessionId) {
|
|
872
|
+
allRecords = allRecords.filter((r) => r.session_id === params.sessionId);
|
|
873
|
+
}
|
|
874
|
+
if (params.agentId) {
|
|
875
|
+
const allowed = new Set(
|
|
876
|
+
[...sessions.values()].filter((s) => s.agent_id === params.agentId).map((s) => s.id)
|
|
877
|
+
);
|
|
878
|
+
allRecords = allRecords.filter((r) => allowed.has(r.session_id));
|
|
879
|
+
}
|
|
859
880
|
if (params.agentType) {
|
|
860
881
|
const allowed = new Set(
|
|
861
882
|
[...sessions.values()].filter((s) => (agents.get(s.agent_id)?.agent_type || "") === params.agentType).map((s) => s.id)
|
|
@@ -865,6 +886,15 @@ var init_json_storage = __esm({
|
|
|
865
886
|
if (params.decision) {
|
|
866
887
|
allRecords = allRecords.filter((r) => r.decision === params.decision);
|
|
867
888
|
}
|
|
889
|
+
if (params.riskLevel) {
|
|
890
|
+
allRecords = allRecords.filter((r) => r.risk_level === params.riskLevel);
|
|
891
|
+
}
|
|
892
|
+
if (params.fromTime) {
|
|
893
|
+
allRecords = allRecords.filter((r) => r.called_at >= params.fromTime);
|
|
894
|
+
}
|
|
895
|
+
if (params.toTime) {
|
|
896
|
+
allRecords = allRecords.filter((r) => r.called_at <= params.toTime);
|
|
897
|
+
}
|
|
868
898
|
return allRecords.length;
|
|
869
899
|
}
|
|
870
900
|
getStorageStats() {
|
|
@@ -1121,6 +1151,10 @@ CREATE INDEX IF NOT EXISTS idx_tool_calls_decision ON tool_calls(decision, calle
|
|
|
1121
1151
|
conditions.push("tc.session_id = ?");
|
|
1122
1152
|
values.push(params.sessionId);
|
|
1123
1153
|
}
|
|
1154
|
+
if (params.agentId) {
|
|
1155
|
+
conditions.push("s.agent_id = ?");
|
|
1156
|
+
values.push(params.agentId);
|
|
1157
|
+
}
|
|
1124
1158
|
if (params.agentType) {
|
|
1125
1159
|
conditions.push("a.agent_type = ?");
|
|
1126
1160
|
values.push(params.agentType);
|
|
@@ -1129,6 +1163,18 @@ CREATE INDEX IF NOT EXISTS idx_tool_calls_decision ON tool_calls(decision, calle
|
|
|
1129
1163
|
conditions.push("tc.decision = ?");
|
|
1130
1164
|
values.push(params.decision);
|
|
1131
1165
|
}
|
|
1166
|
+
if (params.riskLevel) {
|
|
1167
|
+
conditions.push("tc.risk_level = ?");
|
|
1168
|
+
values.push(params.riskLevel);
|
|
1169
|
+
}
|
|
1170
|
+
if (params.fromTime) {
|
|
1171
|
+
conditions.push("tc.called_at >= ?");
|
|
1172
|
+
values.push(params.fromTime);
|
|
1173
|
+
}
|
|
1174
|
+
if (params.toTime) {
|
|
1175
|
+
conditions.push("tc.called_at <= ?");
|
|
1176
|
+
values.push(params.toTime);
|
|
1177
|
+
}
|
|
1132
1178
|
const where = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
1133
1179
|
const limit = params.limit || 50;
|
|
1134
1180
|
const offset = params.offset || 0;
|
|
@@ -1143,14 +1189,34 @@ CREATE INDEX IF NOT EXISTS idx_tool_calls_decision ON tool_calls(decision, calle
|
|
|
1143
1189
|
countToolCalls(params) {
|
|
1144
1190
|
const conditions = [];
|
|
1145
1191
|
const values = [];
|
|
1146
|
-
if (params.
|
|
1147
|
-
conditions.push("tc.
|
|
1148
|
-
values.push(params.
|
|
1192
|
+
if (params.sessionId) {
|
|
1193
|
+
conditions.push("tc.session_id = ?");
|
|
1194
|
+
values.push(params.sessionId);
|
|
1195
|
+
}
|
|
1196
|
+
if (params.agentId) {
|
|
1197
|
+
conditions.push("s.agent_id = ?");
|
|
1198
|
+
values.push(params.agentId);
|
|
1149
1199
|
}
|
|
1150
1200
|
if (params.agentType) {
|
|
1151
1201
|
conditions.push("a.agent_type = ?");
|
|
1152
1202
|
values.push(params.agentType);
|
|
1153
1203
|
}
|
|
1204
|
+
if (params.decision) {
|
|
1205
|
+
conditions.push("tc.decision = ?");
|
|
1206
|
+
values.push(params.decision);
|
|
1207
|
+
}
|
|
1208
|
+
if (params.riskLevel) {
|
|
1209
|
+
conditions.push("tc.risk_level = ?");
|
|
1210
|
+
values.push(params.riskLevel);
|
|
1211
|
+
}
|
|
1212
|
+
if (params.fromTime) {
|
|
1213
|
+
conditions.push("tc.called_at >= ?");
|
|
1214
|
+
values.push(params.fromTime);
|
|
1215
|
+
}
|
|
1216
|
+
if (params.toTime) {
|
|
1217
|
+
conditions.push("tc.called_at <= ?");
|
|
1218
|
+
values.push(params.toTime);
|
|
1219
|
+
}
|
|
1154
1220
|
const where = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
1155
1221
|
const row = this.db.prepare(
|
|
1156
1222
|
`SELECT COUNT(*) as total FROM tool_calls tc
|
|
@@ -1343,7 +1409,7 @@ var import_zod = require("zod");
|
|
|
1343
1409
|
|
|
1344
1410
|
// src/version.ts
|
|
1345
1411
|
init_cjs_shims();
|
|
1346
|
-
var _version = true ? "0.
|
|
1412
|
+
var _version = true ? "0.9.0" : (() => {
|
|
1347
1413
|
try {
|
|
1348
1414
|
const require2 = createRequire(importMetaUrl);
|
|
1349
1415
|
const pkg = require2("../package.json");
|
|
@@ -1372,18 +1438,23 @@ var AgentGateInputSchema = import_zod.z.object({
|
|
|
1372
1438
|
text: import_zod.z.string().default(""),
|
|
1373
1439
|
actions: import_zod.z.array(import_zod.z.object({
|
|
1374
1440
|
action_type: import_zod.z.string(),
|
|
1375
|
-
action_detail: import_zod.z.string()
|
|
1441
|
+
action_detail: import_zod.z.string(),
|
|
1442
|
+
output: import_zod.z.string().optional().describe("\u5DE5\u5177\u8FD4\u56DE\u5185\u5BB9\uFF1Bask_user_question \u7684\u7528\u6237\u56DE\u7B54\u9760\u5B83\u4F20\u7ED9 AgentMoss \u5224\u6388\u6743")
|
|
1376
1443
|
})).default([])
|
|
1377
1444
|
})).default([]),
|
|
1378
1445
|
action_history: import_zod.z.array(import_zod.z.object({
|
|
1379
1446
|
action_type: import_zod.z.string(),
|
|
1380
|
-
action_detail: import_zod.z.string()
|
|
1447
|
+
action_detail: import_zod.z.string(),
|
|
1448
|
+
// 授权类规则(改密码 / 删用户)靠 ask_user_question 的 output 判断用户是否已确认。
|
|
1449
|
+
// 此前 schema 里没有这个字段,Agent 传了也会被剥掉 → 必然判成「未授权」。
|
|
1450
|
+
output: import_zod.z.string().optional().describe("\u5DE5\u5177\u8FD4\u56DE\u5185\u5BB9\uFF1Bask_user_question \u7684\u7528\u6237\u56DE\u7B54\u9760\u5B83\u4F20\u7ED9 AgentMoss \u5224\u6388\u6743")
|
|
1381
1451
|
})).default([]),
|
|
1382
1452
|
session_history: import_zod.z.array(import_zod.z.object({
|
|
1383
1453
|
session_id: import_zod.z.string(),
|
|
1384
1454
|
action_history: import_zod.z.array(import_zod.z.object({
|
|
1385
1455
|
action_type: import_zod.z.string(),
|
|
1386
|
-
action_detail: import_zod.z.string()
|
|
1456
|
+
action_detail: import_zod.z.string(),
|
|
1457
|
+
output: import_zod.z.string().optional()
|
|
1387
1458
|
})).default([])
|
|
1388
1459
|
})).default([]).describe("\u591A session \u5386\u53F2\u52A8\u4F5C\uFF08\u53EF\u9009\uFF09\uFF1A\u4F9B AgentMoss L2.4 \u5F62\u5F0F\u5316\u5F15\u64CE\u8DE8\u4F1A\u8BDD\u9A8C\u8BC1"),
|
|
1389
1460
|
metadata: import_zod.z.record(import_zod.z.unknown()).optional()
|
|
@@ -1428,20 +1499,23 @@ init_multi_session();
|
|
|
1428
1499
|
function normalize(input, systemContext) {
|
|
1429
1500
|
const actionHistory = input.action_history.map((h) => ({
|
|
1430
1501
|
action_type: h.action_type,
|
|
1431
|
-
action_detail: h.action_detail
|
|
1502
|
+
action_detail: h.action_detail,
|
|
1503
|
+
output: h.output ?? ""
|
|
1432
1504
|
}));
|
|
1433
1505
|
const sessionHistory = (input.session_history || []).map((s) => ({
|
|
1434
1506
|
session_id: s.session_id,
|
|
1435
1507
|
action_history: s.action_history.map((h) => ({
|
|
1436
1508
|
action_type: h.action_type,
|
|
1437
|
-
action_detail: h.action_detail
|
|
1509
|
+
action_detail: h.action_detail,
|
|
1510
|
+
output: h.output ?? ""
|
|
1438
1511
|
}))
|
|
1439
1512
|
}));
|
|
1440
1513
|
const promptHistory = input.prompt_history.map((t) => ({
|
|
1441
1514
|
text: t.text,
|
|
1442
1515
|
actions: t.actions.map((a) => ({
|
|
1443
1516
|
action_type: a.action_type,
|
|
1444
|
-
action_detail: a.action_detail
|
|
1517
|
+
action_detail: a.action_detail,
|
|
1518
|
+
output: a.output ?? ""
|
|
1445
1519
|
}))
|
|
1446
1520
|
}));
|
|
1447
1521
|
const toolName = input.tool_name || input.a_next?.action_type || "unknown";
|
|
@@ -1755,13 +1829,22 @@ async function sessionsRoute(c) {
|
|
|
1755
1829
|
return c.json({ session_id: sessionId, tool_calls: rows });
|
|
1756
1830
|
}
|
|
1757
1831
|
async function toolCallsRoute(c) {
|
|
1758
|
-
const
|
|
1759
|
-
|
|
1760
|
-
const
|
|
1832
|
+
const sessionId = c.req.query("session_id") || void 0;
|
|
1833
|
+
let agentId = c.req.query("agent_id") || void 0;
|
|
1834
|
+
const decision = c.req.query("decision") || void 0;
|
|
1835
|
+
const riskLevel = c.req.query("risk_level") || void 0;
|
|
1836
|
+
const fromTime = c.req.query("from") || void 0;
|
|
1837
|
+
const toTime = c.req.query("to") || void 0;
|
|
1838
|
+
const rawLimit = parseInt(c.req.query("limit") || "50", 10);
|
|
1839
|
+
const limit = Number.isFinite(rawLimit) ? Math.min(Math.max(rawLimit, 1), 500) : 50;
|
|
1840
|
+
const rawOffset = parseInt(c.req.query("offset") || "0", 10);
|
|
1841
|
+
const offset = Number.isFinite(rawOffset) && rawOffset > 0 ? rawOffset : 0;
|
|
1761
1842
|
const bound = boundAgentOf(c.get("principal") || "");
|
|
1843
|
+
if (bound) agentId = void 0;
|
|
1762
1844
|
const agentType = bound || void 0;
|
|
1763
|
-
const
|
|
1764
|
-
const
|
|
1845
|
+
const filter = { sessionId, agentId, agentType, decision, riskLevel, fromTime, toTime };
|
|
1846
|
+
const total = countToolCalls(filter);
|
|
1847
|
+
const data = queryToolCalls({ ...filter, limit, offset });
|
|
1765
1848
|
return c.json({ total, data });
|
|
1766
1849
|
}
|
|
1767
1850
|
async function agentsRoute(c) {
|