@kenhkl/agent-gate 0.9.0 → 0.9.2
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/dashboard.html +175 -3
- package/dist/shared/storage/db.d.ts +9 -0
- package/dist/shared/storage/db.js +228 -47
- package/dist/v1/cli.js +344 -54
- package/dist/v1/server.js +251 -54
- package/dist/v3/cli.js +295 -97
- package/package.json +1 -1
package/dist/v3/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.9.
|
|
53
|
+
_version = true ? "0.9.2" : (() => {
|
|
54
54
|
try {
|
|
55
55
|
const require2 = createRequire(importMetaUrl);
|
|
56
56
|
const pkg = require2("../package.json");
|
|
@@ -76,6 +76,8 @@ __export(security_exports, {
|
|
|
76
76
|
agentInflight: () => agentInflight,
|
|
77
77
|
agentTokens: () => agentTokens,
|
|
78
78
|
allowedOrigins: () => allowedOrigins,
|
|
79
|
+
archiveKeepRecords: () => archiveKeepRecords,
|
|
80
|
+
archiveThresholdRecords: () => archiveThresholdRecords,
|
|
79
81
|
authConfigError: () => authConfigError,
|
|
80
82
|
authEnabled: () => authEnabled,
|
|
81
83
|
authMode: () => authMode,
|
|
@@ -88,6 +90,8 @@ __export(security_exports, {
|
|
|
88
90
|
checkToken: () => checkToken,
|
|
89
91
|
cookiePathAllowed: () => cookiePathAllowed,
|
|
90
92
|
describe: () => describe,
|
|
93
|
+
diskDegradePercent: () => diskDegradePercent,
|
|
94
|
+
diskWarnPercent: () => diskWarnPercent,
|
|
91
95
|
ensureAutoToken: () => ensureAutoToken,
|
|
92
96
|
ensurePrivateDir: () => ensurePrivateDir,
|
|
93
97
|
failFastOnAuthError: () => failFastOnAuthError,
|
|
@@ -100,6 +104,7 @@ __export(security_exports, {
|
|
|
100
104
|
maxConnections: () => maxConnections,
|
|
101
105
|
maxInflight: () => maxInflight,
|
|
102
106
|
maxQueue: () => maxQueue,
|
|
107
|
+
maxRecordBytes: () => maxRecordBytes,
|
|
103
108
|
normalizeOrigin: () => normalizeOrigin,
|
|
104
109
|
noteQueueReject: () => noteQueueReject,
|
|
105
110
|
noteSessionAccess: () => noteSessionAccess,
|
|
@@ -385,6 +390,21 @@ function bindAgent(principal, agentType) {
|
|
|
385
390
|
function maxBodyBytes() {
|
|
386
391
|
return envInt("AGENT_GATE_MAX_BODY_BYTES", 16 * 1024 * 1024);
|
|
387
392
|
}
|
|
393
|
+
function maxRecordBytes() {
|
|
394
|
+
return envInt("AGENT_GATE_MAX_RECORD_BYTES", 1024 * 1024);
|
|
395
|
+
}
|
|
396
|
+
function archiveThresholdRecords() {
|
|
397
|
+
return envInt("AGENT_GATE_ARCHIVE_THRESHOLD", 1e5);
|
|
398
|
+
}
|
|
399
|
+
function archiveKeepRecords() {
|
|
400
|
+
return envInt("AGENT_GATE_ARCHIVE_KEEP", 5e4);
|
|
401
|
+
}
|
|
402
|
+
function diskWarnPercent() {
|
|
403
|
+
return envInt("AGENT_GATE_DISK_WARN_PERCENT", 5);
|
|
404
|
+
}
|
|
405
|
+
function diskDegradePercent() {
|
|
406
|
+
return envInt("AGENT_GATE_DISK_DEGRADE_PERCENT", 2);
|
|
407
|
+
}
|
|
388
408
|
function maxInflight() {
|
|
389
409
|
return poolLimit("biz");
|
|
390
410
|
}
|
|
@@ -603,6 +623,66 @@ var init_security = __esm({
|
|
|
603
623
|
}
|
|
604
624
|
});
|
|
605
625
|
|
|
626
|
+
// src/shared/storage/record-guard.ts
|
|
627
|
+
function clipText(value, limit = maxRecordBytes()) {
|
|
628
|
+
const s = String(value ?? "");
|
|
629
|
+
if (limit <= 0 || s.length <= limit) return s;
|
|
630
|
+
const head = s.slice(0, limit);
|
|
631
|
+
const digest = (0, import_crypto.createHash)("sha256").update(s).digest("hex").slice(0, 16);
|
|
632
|
+
return `${head}\u2026[truncated ${s.length - limit}B sha256:${digest}]`;
|
|
633
|
+
}
|
|
634
|
+
function diskFreePercent(targetPath) {
|
|
635
|
+
try {
|
|
636
|
+
const st = (0, import_fs.statfsSync)((0, import_path.dirname)(targetPath));
|
|
637
|
+
const total = Number(st.blocks) || 0;
|
|
638
|
+
const avail = Number(st.bavail) || 0;
|
|
639
|
+
if (!total) return 100;
|
|
640
|
+
return avail / total * 100;
|
|
641
|
+
} catch {
|
|
642
|
+
return 100;
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
function shouldDegradeWrites(targetPath) {
|
|
646
|
+
const degrade = diskDegradePercent();
|
|
647
|
+
if (degrade <= 0) return false;
|
|
648
|
+
return diskFreePercent(targetPath) < degrade;
|
|
649
|
+
}
|
|
650
|
+
function degradeRecord(rec) {
|
|
651
|
+
const command = String(rec.command ?? "");
|
|
652
|
+
const clipped = command.length > DEGRADE_COMMAND_BYTES ? `${command.slice(0, DEGRADE_COMMAND_BYTES)}\u2026[degraded]` : command;
|
|
653
|
+
return {
|
|
654
|
+
...rec,
|
|
655
|
+
command: clipped,
|
|
656
|
+
action_detail: String(rec.action_detail ?? "") > "" ? String(rec.action_detail).slice(0, DEGRADE_COMMAND_BYTES) : "",
|
|
657
|
+
description: "",
|
|
658
|
+
reason: String(rec.reason ?? "").slice(0, 256)
|
|
659
|
+
};
|
|
660
|
+
}
|
|
661
|
+
function prepareRecordForStorage(rec, targetPath) {
|
|
662
|
+
let out = {
|
|
663
|
+
...rec,
|
|
664
|
+
command: clipText(rec.command),
|
|
665
|
+
action_detail: clipText(rec.action_detail),
|
|
666
|
+
reason: clipText(rec.reason, 4096),
|
|
667
|
+
description: clipText(rec.description, 4096)
|
|
668
|
+
};
|
|
669
|
+
const degraded = shouldDegradeWrites(targetPath);
|
|
670
|
+
if (degraded) out = degradeRecord(out);
|
|
671
|
+
return { record: out, degraded };
|
|
672
|
+
}
|
|
673
|
+
var import_crypto, import_fs, import_path, DEGRADE_COMMAND_BYTES;
|
|
674
|
+
var init_record_guard = __esm({
|
|
675
|
+
"src/shared/storage/record-guard.ts"() {
|
|
676
|
+
"use strict";
|
|
677
|
+
init_cjs_shims();
|
|
678
|
+
import_crypto = require("crypto");
|
|
679
|
+
import_fs = require("fs");
|
|
680
|
+
import_path = require("path");
|
|
681
|
+
init_security();
|
|
682
|
+
DEGRADE_COMMAND_BYTES = 512;
|
|
683
|
+
}
|
|
684
|
+
});
|
|
685
|
+
|
|
606
686
|
// src/shared/storage/json-storage.ts
|
|
607
687
|
var json_storage_exports = {};
|
|
608
688
|
__export(json_storage_exports, {
|
|
@@ -613,17 +693,18 @@ function nowISO() {
|
|
|
613
693
|
}
|
|
614
694
|
function getDefaultDataDir() {
|
|
615
695
|
const home = process.env.HOME || process.env.USERPROFILE || "/tmp";
|
|
616
|
-
const xdgData = process.env.XDG_DATA_HOME || (0,
|
|
617
|
-
return (0,
|
|
696
|
+
const xdgData = process.env.XDG_DATA_HOME || (0, import_path2.join)(home, ".local", "share");
|
|
697
|
+
return (0, import_path2.join)(xdgData, "agent_gate", "storage");
|
|
618
698
|
}
|
|
619
|
-
var
|
|
699
|
+
var import_fs2, import_path2, JsonStorage;
|
|
620
700
|
var init_json_storage = __esm({
|
|
621
701
|
"src/shared/storage/json-storage.ts"() {
|
|
622
702
|
"use strict";
|
|
623
703
|
init_cjs_shims();
|
|
624
|
-
|
|
625
|
-
|
|
704
|
+
import_fs2 = require("fs");
|
|
705
|
+
import_path2 = require("path");
|
|
626
706
|
init_security();
|
|
707
|
+
init_record_guard();
|
|
627
708
|
JsonStorage = class {
|
|
628
709
|
dataDir;
|
|
629
710
|
agentsPath;
|
|
@@ -636,11 +717,11 @@ var init_json_storage = __esm({
|
|
|
636
717
|
sessionLocks = /* @__PURE__ */ new Map();
|
|
637
718
|
constructor(dataDir) {
|
|
638
719
|
this.dataDir = dataDir || process.env.AGENT_GATE_DATA_DIR || getDefaultDataDir();
|
|
639
|
-
this.agentsPath = (0,
|
|
640
|
-
this.sessionsPath = (0,
|
|
641
|
-
this.toolCallsDir = (0,
|
|
642
|
-
if (!(0,
|
|
643
|
-
if (!(0,
|
|
720
|
+
this.agentsPath = (0, import_path2.join)(this.dataDir, "agents.json");
|
|
721
|
+
this.sessionsPath = (0, import_path2.join)(this.dataDir, "sessions.json");
|
|
722
|
+
this.toolCallsDir = (0, import_path2.join)(this.dataDir, "tool_calls");
|
|
723
|
+
if (!(0, import_fs2.existsSync)(this.dataDir)) (0, import_fs2.mkdirSync)(this.dataDir, { recursive: true, mode: 448 });
|
|
724
|
+
if (!(0, import_fs2.existsSync)(this.toolCallsDir)) (0, import_fs2.mkdirSync)(this.toolCallsDir, { recursive: true, mode: 448 });
|
|
644
725
|
this.hardenStoragePermissions();
|
|
645
726
|
this.nextId = this.recoverNextId();
|
|
646
727
|
}
|
|
@@ -652,10 +733,10 @@ var init_json_storage = __esm({
|
|
|
652
733
|
const uid = process.getuid?.();
|
|
653
734
|
const tighten = (p, mode) => {
|
|
654
735
|
try {
|
|
655
|
-
const st = (0,
|
|
736
|
+
const st = (0, import_fs2.statSync)(p);
|
|
656
737
|
if (st.isSymbolicLink()) return;
|
|
657
738
|
if (uid !== void 0 && st.uid !== uid) return;
|
|
658
|
-
if ((st.mode & 511) !== mode) (0,
|
|
739
|
+
if ((st.mode & 511) !== mode) (0, import_fs2.chmodSync)(p, mode);
|
|
659
740
|
} catch {
|
|
660
741
|
}
|
|
661
742
|
};
|
|
@@ -664,9 +745,9 @@ var init_json_storage = __esm({
|
|
|
664
745
|
tighten(this.agentsPath, 384);
|
|
665
746
|
tighten(this.sessionsPath, 384);
|
|
666
747
|
try {
|
|
667
|
-
for (const f of (0,
|
|
748
|
+
for (const f of (0, import_fs2.readdirSync)(this.toolCallsDir)) {
|
|
668
749
|
if (f.endsWith(".json") || f.endsWith(".tmp")) {
|
|
669
|
-
tighten((0,
|
|
750
|
+
tighten((0, import_path2.join)(this.toolCallsDir, f), 384);
|
|
670
751
|
}
|
|
671
752
|
}
|
|
672
753
|
} catch {
|
|
@@ -676,9 +757,9 @@ var init_json_storage = __esm({
|
|
|
676
757
|
recoverNextId() {
|
|
677
758
|
let maxId = 0;
|
|
678
759
|
try {
|
|
679
|
-
const files = (0,
|
|
760
|
+
const files = (0, import_fs2.readdirSync)(this.toolCallsDir).filter((f) => f.endsWith(".json"));
|
|
680
761
|
for (const file of files) {
|
|
681
|
-
const records = this.readJsonFile((0,
|
|
762
|
+
const records = this.readJsonFile((0, import_path2.join)(this.toolCallsDir, file), []);
|
|
682
763
|
for (const r of records) {
|
|
683
764
|
if (r.id > maxId) maxId = r.id;
|
|
684
765
|
}
|
|
@@ -689,19 +770,19 @@ var init_json_storage = __esm({
|
|
|
689
770
|
}
|
|
690
771
|
readJsonFile(path11, fallback2) {
|
|
691
772
|
try {
|
|
692
|
-
if (!(0,
|
|
693
|
-
return JSON.parse((0,
|
|
773
|
+
if (!(0, import_fs2.existsSync)(path11)) return fallback2;
|
|
774
|
+
return JSON.parse((0, import_fs2.readFileSync)(path11, "utf-8"));
|
|
694
775
|
} catch {
|
|
695
776
|
return fallback2;
|
|
696
777
|
}
|
|
697
778
|
}
|
|
698
779
|
/** 原子写入:先写 .tmp 再 rename(rename 保留 tmp 的 0600 权限) */
|
|
699
780
|
writeJsonFile(path11, data) {
|
|
700
|
-
const dir2 = (0,
|
|
701
|
-
if (!(0,
|
|
781
|
+
const dir2 = (0, import_path2.dirname)(path11);
|
|
782
|
+
if (!(0, import_fs2.existsSync)(dir2)) (0, import_fs2.mkdirSync)(dir2, { recursive: true, mode: 448 });
|
|
702
783
|
const tmp = path11 + ".tmp";
|
|
703
|
-
(0,
|
|
704
|
-
(0,
|
|
784
|
+
(0, import_fs2.writeFileSync)(tmp, JSON.stringify(data, null, 2), { encoding: "utf-8", mode: 384 });
|
|
785
|
+
(0, import_fs2.renameSync)(tmp, path11);
|
|
705
786
|
}
|
|
706
787
|
loadAgents() {
|
|
707
788
|
const raw = this.readJsonFile(this.agentsPath, {});
|
|
@@ -719,12 +800,12 @@ var init_json_storage = __esm({
|
|
|
719
800
|
}
|
|
720
801
|
loadToolCalls(sessionId) {
|
|
721
802
|
return this.readJsonFile(
|
|
722
|
-
(0,
|
|
803
|
+
(0, import_path2.join)(this.toolCallsDir, `${sessionId}.json`),
|
|
723
804
|
[]
|
|
724
805
|
);
|
|
725
806
|
}
|
|
726
807
|
saveToolCalls(sessionId, records) {
|
|
727
|
-
this.writeJsonFile((0,
|
|
808
|
+
this.writeJsonFile((0, import_path2.join)(this.toolCallsDir, `${sessionId}.json`), records);
|
|
728
809
|
}
|
|
729
810
|
getOrCreateAgent(agentType, hostname, version3 = "") {
|
|
730
811
|
const agents = this.loadAgents();
|
|
@@ -769,6 +850,10 @@ var init_json_storage = __esm({
|
|
|
769
850
|
return Math.max(...records.map((r) => r.seq)) + 1;
|
|
770
851
|
}
|
|
771
852
|
insertToolCall(record) {
|
|
853
|
+
record = prepareRecordForStorage(
|
|
854
|
+
record,
|
|
855
|
+
this.dataDir
|
|
856
|
+
).record;
|
|
772
857
|
const sessionId = record.session_id;
|
|
773
858
|
const prev = this.sessionLocks.get(sessionId) ?? Promise.resolve();
|
|
774
859
|
const next = prev.then(() => {
|
|
@@ -806,9 +891,9 @@ var init_json_storage = __esm({
|
|
|
806
891
|
allRecords = records.map((r) => this.enrichRecord(r, sessions, agents));
|
|
807
892
|
} else {
|
|
808
893
|
try {
|
|
809
|
-
const files = (0,
|
|
894
|
+
const files = (0, import_fs2.readdirSync)(this.toolCallsDir).filter((f) => f.endsWith(".json"));
|
|
810
895
|
for (const file of files) {
|
|
811
|
-
const records = this.readJsonFile((0,
|
|
896
|
+
const records = this.readJsonFile((0, import_path2.join)(this.toolCallsDir, file), []);
|
|
812
897
|
allRecords.push(...records.map((r) => this.enrichRecord(r, sessions, agents)));
|
|
813
898
|
}
|
|
814
899
|
} catch {
|
|
@@ -842,9 +927,9 @@ var init_json_storage = __esm({
|
|
|
842
927
|
const agents = this.loadAgents();
|
|
843
928
|
let allRecords = [];
|
|
844
929
|
try {
|
|
845
|
-
const files = (0,
|
|
930
|
+
const files = (0, import_fs2.readdirSync)(this.toolCallsDir).filter((f) => f.endsWith(".json"));
|
|
846
931
|
for (const file of files) {
|
|
847
|
-
const records = this.readJsonFile((0,
|
|
932
|
+
const records = this.readJsonFile((0, import_path2.join)(this.toolCallsDir, file), []);
|
|
848
933
|
allRecords.push(...records);
|
|
849
934
|
}
|
|
850
935
|
} catch {
|
|
@@ -883,12 +968,12 @@ var init_json_storage = __esm({
|
|
|
883
968
|
let jsonFiles = 0;
|
|
884
969
|
let jsonBytes = 0;
|
|
885
970
|
try {
|
|
886
|
-
const files = (0,
|
|
971
|
+
const files = (0, import_fs2.readdirSync)(this.toolCallsDir).filter((f) => f.endsWith(".json"));
|
|
887
972
|
for (const file of files) {
|
|
888
|
-
const stat = (0,
|
|
973
|
+
const stat = (0, import_fs2.statSync)((0, import_path2.join)(this.toolCallsDir, file));
|
|
889
974
|
jsonFiles++;
|
|
890
975
|
jsonBytes += stat.size;
|
|
891
|
-
const records = this.readJsonFile((0,
|
|
976
|
+
const records = this.readJsonFile((0, import_path2.join)(this.toolCallsDir, file), []);
|
|
892
977
|
toolCalls += records.length;
|
|
893
978
|
}
|
|
894
979
|
} catch {
|
|
@@ -898,9 +983,9 @@ var init_json_storage = __esm({
|
|
|
898
983
|
clearToolCalls() {
|
|
899
984
|
let removed = 0;
|
|
900
985
|
try {
|
|
901
|
-
const files = (0,
|
|
986
|
+
const files = (0, import_fs2.readdirSync)(this.toolCallsDir).filter((f) => f.endsWith(".json"));
|
|
902
987
|
for (const file of files) {
|
|
903
|
-
(0,
|
|
988
|
+
(0, import_fs2.unlinkSync)((0, import_path2.join)(this.toolCallsDir, file));
|
|
904
989
|
removed++;
|
|
905
990
|
}
|
|
906
991
|
} catch {
|
|
@@ -918,6 +1003,49 @@ var init_json_storage = __esm({
|
|
|
918
1003
|
hostname: agent?.hostname || ""
|
|
919
1004
|
};
|
|
920
1005
|
}
|
|
1006
|
+
/**
|
|
1007
|
+
* 归档最老的记录:JSON 模式下每个 session 一个文件,这里把所有 session 的记录
|
|
1008
|
+
* 汇总排序,最老的 (total - keep) 条写进 `<dataDir>/archive/*.jsonl.gz`,
|
|
1009
|
+
* 再从各自的 session 文件里移除。数据不丢,只是不在主目录了。
|
|
1010
|
+
*/
|
|
1011
|
+
archiveOldRecords(keep) {
|
|
1012
|
+
if (keep <= 0 || !(0, import_fs2.existsSync)(this.toolCallsDir)) return { archived: 0, file: "" };
|
|
1013
|
+
const bySession = /* @__PURE__ */ new Map();
|
|
1014
|
+
let total = 0;
|
|
1015
|
+
for (const f of (0, import_fs2.readdirSync)(this.toolCallsDir)) {
|
|
1016
|
+
if (!f.endsWith(".json")) continue;
|
|
1017
|
+
const sid = f.slice(0, -".json".length);
|
|
1018
|
+
const recs = this.loadToolCalls(sid);
|
|
1019
|
+
if (recs.length) {
|
|
1020
|
+
bySession.set(sid, recs);
|
|
1021
|
+
total += recs.length;
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
if (total <= keep) return { archived: 0, file: "" };
|
|
1025
|
+
const flat = [];
|
|
1026
|
+
for (const [sid, recs] of bySession) for (const rec of recs) flat.push({ sid, rec });
|
|
1027
|
+
flat.sort((a, b) => String(a.rec.called_at).localeCompare(String(b.rec.called_at)));
|
|
1028
|
+
const archiveCount = total - keep;
|
|
1029
|
+
const toArchive = flat.slice(0, archiveCount);
|
|
1030
|
+
const archiveIds = new Set(toArchive.map((x) => String(x.rec.id)));
|
|
1031
|
+
const { mkdirSync: mkdirSync5, writeFileSync: writeFileSync4 } = require("fs");
|
|
1032
|
+
const { join: join12 } = require("path");
|
|
1033
|
+
const { gzipSync } = require("zlib");
|
|
1034
|
+
const archiveDir = join12(this.dataDir, "archive");
|
|
1035
|
+
if (!(0, import_fs2.existsSync)(archiveDir)) mkdirSync5(archiveDir, { recursive: true, mode: 448 });
|
|
1036
|
+
const stamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
|
|
1037
|
+
const file = join12(archiveDir, `tool_calls-${stamp}.jsonl.gz`);
|
|
1038
|
+
const payload = toArchive.map((x) => JSON.stringify(x.rec)).join("\n") + "\n";
|
|
1039
|
+
writeFileSync4(file, gzipSync(Buffer.from(payload, "utf-8")), { mode: 384 });
|
|
1040
|
+
for (const [sid, recs] of bySession) {
|
|
1041
|
+
const remain = recs.filter((r) => !archiveIds.has(String(r.id)));
|
|
1042
|
+
if (remain.length !== recs.length) this.saveToolCalls(sid, remain);
|
|
1043
|
+
}
|
|
1044
|
+
return { archived: toArchive.length, file };
|
|
1045
|
+
}
|
|
1046
|
+
/** JSON 模式没有需要回收的数据库页,归档已把文件挪走。 */
|
|
1047
|
+
vacuum() {
|
|
1048
|
+
}
|
|
921
1049
|
getAgentsList(agentType) {
|
|
922
1050
|
const agents = this.loadAgents();
|
|
923
1051
|
const sessions = this.loadSessions();
|
|
@@ -952,9 +1080,9 @@ var init_json_storage = __esm({
|
|
|
952
1080
|
getTimeline(limit = 100) {
|
|
953
1081
|
const buckets = /* @__PURE__ */ new Map();
|
|
954
1082
|
try {
|
|
955
|
-
const files = (0,
|
|
1083
|
+
const files = (0, import_fs2.readdirSync)(this.toolCallsDir).filter((f) => f.endsWith(".json"));
|
|
956
1084
|
for (const file of files) {
|
|
957
|
-
const records = this.readJsonFile((0,
|
|
1085
|
+
const records = this.readJsonFile((0, import_path2.join)(this.toolCallsDir, file), []);
|
|
958
1086
|
for (const r of records) {
|
|
959
1087
|
const minute = r.called_at.replace(/(\d{4}-\d{2}-\d{2}) (\d{2}:\d{2}):\d{2}/, "$1T$2");
|
|
960
1088
|
const bucket = buckets.get(minute) || { allow: 0, deny: 0 };
|
|
@@ -985,16 +1113,17 @@ __export(sqlite_storage_exports, {
|
|
|
985
1113
|
});
|
|
986
1114
|
function getDefaultDbPath() {
|
|
987
1115
|
const home = process.env.HOME || process.env.USERPROFILE || "/tmp";
|
|
988
|
-
const xdgData = process.env.XDG_DATA_HOME || (0,
|
|
989
|
-
return (0,
|
|
1116
|
+
const xdgData = process.env.XDG_DATA_HOME || (0, import_path3.join)(home, ".local", "share");
|
|
1117
|
+
return (0, import_path3.join)(xdgData, "agent_gate", "agent_gate_ts.db");
|
|
990
1118
|
}
|
|
991
|
-
var
|
|
1119
|
+
var import_fs3, import_path3, SCHEMA, SqliteStorage;
|
|
992
1120
|
var init_sqlite_storage = __esm({
|
|
993
1121
|
"src/shared/storage/sqlite-storage.ts"() {
|
|
994
1122
|
"use strict";
|
|
995
1123
|
init_cjs_shims();
|
|
996
|
-
|
|
997
|
-
|
|
1124
|
+
import_fs3 = require("fs");
|
|
1125
|
+
import_path3 = require("path");
|
|
1126
|
+
init_record_guard();
|
|
998
1127
|
SCHEMA = `
|
|
999
1128
|
CREATE TABLE IF NOT EXISTS agents (
|
|
1000
1129
|
id TEXT PRIMARY KEY,
|
|
@@ -1034,6 +1163,7 @@ CREATE TABLE IF NOT EXISTS tool_calls (
|
|
|
1034
1163
|
reason TEXT DEFAULT '',
|
|
1035
1164
|
confidence INTEGER DEFAULT 0,
|
|
1036
1165
|
analysis_duration_ms REAL DEFAULT 0,
|
|
1166
|
+
violation_graph TEXT DEFAULT '{}',
|
|
1037
1167
|
called_at TEXT DEFAULT (datetime('now')),
|
|
1038
1168
|
UNIQUE(session_id, seq)
|
|
1039
1169
|
);
|
|
@@ -1054,12 +1184,23 @@ CREATE INDEX IF NOT EXISTS idx_tool_calls_decision ON tool_calls(decision, calle
|
|
|
1054
1184
|
);
|
|
1055
1185
|
}
|
|
1056
1186
|
const path11 = dbPath || getDefaultDbPath();
|
|
1057
|
-
const dir2 = (0,
|
|
1058
|
-
if (!(0,
|
|
1187
|
+
const dir2 = (0, import_path3.dirname)(path11);
|
|
1188
|
+
if (!(0, import_fs3.existsSync)(dir2)) (0, import_fs3.mkdirSync)(dir2, { recursive: true });
|
|
1059
1189
|
this.dbPath = path11;
|
|
1060
1190
|
this.db = new Database(path11);
|
|
1061
1191
|
this.db.pragma("journal_mode = WAL");
|
|
1062
1192
|
this.db.exec(SCHEMA);
|
|
1193
|
+
this.ensureColumn("tool_calls", "violation_graph", "violation_graph TEXT DEFAULT '{}'");
|
|
1194
|
+
}
|
|
1195
|
+
/** 幂等补列(旧数据库平滑升级,失败不阻断启动)。 */
|
|
1196
|
+
ensureColumn(table, column, ddl) {
|
|
1197
|
+
try {
|
|
1198
|
+
const cols = this.db.prepare(`PRAGMA table_info(${table})`).all();
|
|
1199
|
+
if (!cols.some((c) => c.name === column)) {
|
|
1200
|
+
this.db.exec(`ALTER TABLE ${table} ADD COLUMN ${ddl}`);
|
|
1201
|
+
}
|
|
1202
|
+
} catch {
|
|
1203
|
+
}
|
|
1063
1204
|
}
|
|
1064
1205
|
static isAvailable() {
|
|
1065
1206
|
try {
|
|
@@ -1089,6 +1230,10 @@ CREATE INDEX IF NOT EXISTS idx_tool_calls_decision ON tool_calls(decision, calle
|
|
|
1089
1230
|
return row.next;
|
|
1090
1231
|
}
|
|
1091
1232
|
insertToolCall(record) {
|
|
1233
|
+
record = prepareRecordForStorage(
|
|
1234
|
+
record,
|
|
1235
|
+
this.dbPath
|
|
1236
|
+
).record;
|
|
1092
1237
|
const result = this.db.transaction((rec) => {
|
|
1093
1238
|
const row = this.db.prepare(
|
|
1094
1239
|
"SELECT COALESCE(MAX(seq), 0) + 1 as next FROM tool_calls WHERE session_id = ?"
|
|
@@ -1097,8 +1242,8 @@ CREATE INDEX IF NOT EXISTS idx_tool_calls_decision ON tool_calls(decision, calle
|
|
|
1097
1242
|
return this.db.prepare(`
|
|
1098
1243
|
INSERT INTO tool_calls (session_id, seq, tool_name, command, description, cwd,
|
|
1099
1244
|
action_type, action_detail, decision, risk_level, risk_type, violated_layers,
|
|
1100
|
-
reason, confidence, analysis_duration_ms)
|
|
1101
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
1245
|
+
reason, confidence, analysis_duration_ms, violation_graph)
|
|
1246
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
1102
1247
|
`).run(
|
|
1103
1248
|
rec.session_id,
|
|
1104
1249
|
seq2,
|
|
@@ -1114,7 +1259,8 @@ CREATE INDEX IF NOT EXISTS idx_tool_calls_decision ON tool_calls(decision, calle
|
|
|
1114
1259
|
rec.violated_layers,
|
|
1115
1260
|
rec.reason,
|
|
1116
1261
|
rec.confidence,
|
|
1117
|
-
rec.analysis_duration_ms
|
|
1262
|
+
rec.analysis_duration_ms,
|
|
1263
|
+
rec.violation_graph || "{}"
|
|
1118
1264
|
);
|
|
1119
1265
|
})(record);
|
|
1120
1266
|
return Number(result.lastInsertRowid);
|
|
@@ -1229,6 +1375,49 @@ CREATE INDEX IF NOT EXISTS idx_tool_calls_decision ON tool_calls(decision, calle
|
|
|
1229
1375
|
})();
|
|
1230
1376
|
return result;
|
|
1231
1377
|
}
|
|
1378
|
+
/**
|
|
1379
|
+
* 把最老的记录归档到本地压缩文件,主库只保留最近 `keep` 条。
|
|
1380
|
+
*
|
|
1381
|
+
* 归档文件是 **JSONL + gzip**(一行一条记录),放在 `<数据库目录>/archive/` 下,
|
|
1382
|
+
* 需要翻旧账时用 `zcat archive/xxx.jsonl.gz | grep ...` 即可 —— 数据不丢,只是
|
|
1383
|
+
* 不在主库里了。写完文件、校验落盘后才删主库行,最后 VACUUM 真正释放磁盘。
|
|
1384
|
+
*/
|
|
1385
|
+
archiveOldRecords(keep) {
|
|
1386
|
+
if (keep <= 0) return { archived: 0, file: "" };
|
|
1387
|
+
const total = this.db.prepare("SELECT COUNT(*) as n FROM tool_calls").get().n;
|
|
1388
|
+
if (total <= keep) return { archived: 0, file: "" };
|
|
1389
|
+
const cutoff = this.db.prepare(
|
|
1390
|
+
"SELECT id FROM tool_calls ORDER BY id LIMIT 1 OFFSET ?"
|
|
1391
|
+
).get(total - keep - 1);
|
|
1392
|
+
if (!cutoff) return { archived: 0, file: "" };
|
|
1393
|
+
const rows = this.db.prepare(
|
|
1394
|
+
"SELECT * FROM tool_calls WHERE id <= ? ORDER BY id"
|
|
1395
|
+
).all(cutoff.id);
|
|
1396
|
+
if (rows.length === 0) return { archived: 0, file: "" };
|
|
1397
|
+
const { writeFileSync: writeFileSync4, mkdirSync: mkdirSync5, existsSync: existsSync12 } = require("fs");
|
|
1398
|
+
const { dirname: dirname6, join: join12 } = require("path");
|
|
1399
|
+
const { gzipSync } = require("zlib");
|
|
1400
|
+
const archiveDir = join12(dirname6(this.dbPath), "archive");
|
|
1401
|
+
if (!existsSync12(archiveDir)) mkdirSync5(archiveDir, { recursive: true, mode: 448 });
|
|
1402
|
+
const stamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
|
|
1403
|
+
const file = join12(archiveDir, `tool_calls-${stamp}.jsonl.gz`);
|
|
1404
|
+
const payload = rows.map((r) => JSON.stringify(r)).join("\n") + "\n";
|
|
1405
|
+
writeFileSync4(file, gzipSync(Buffer.from(payload, "utf-8")), { mode: 384 });
|
|
1406
|
+
const deleted = this.db.transaction(() => {
|
|
1407
|
+
const res = this.db.prepare("DELETE FROM tool_calls WHERE id <= ?").run(cutoff.id);
|
|
1408
|
+
this.db.prepare(`
|
|
1409
|
+
UPDATE sessions SET tool_call_count = (
|
|
1410
|
+
SELECT COUNT(*) FROM tool_calls WHERE tool_calls.session_id = sessions.id
|
|
1411
|
+
)
|
|
1412
|
+
`).run();
|
|
1413
|
+
return Number(res.changes);
|
|
1414
|
+
})();
|
|
1415
|
+
return { archived: deleted, file };
|
|
1416
|
+
}
|
|
1417
|
+
/** 真正释放磁盘空间:DELETE 后必须 VACUUM,否则文件不会变小。 */
|
|
1418
|
+
vacuum() {
|
|
1419
|
+
this.db.exec("VACUUM");
|
|
1420
|
+
}
|
|
1232
1421
|
getAgentsList(agentType) {
|
|
1233
1422
|
const where = agentType ? "WHERE a.agent_type = ?" : "";
|
|
1234
1423
|
return this.db.prepare(`
|
|
@@ -1320,12 +1509,12 @@ function getDb(dbPath) {
|
|
|
1320
1509
|
try {
|
|
1321
1510
|
const Database = require("better-sqlite3");
|
|
1322
1511
|
const { existsSync: existsSync12, mkdirSync: mkdirSync5 } = require("fs");
|
|
1323
|
-
const { join: join12, dirname:
|
|
1512
|
+
const { join: join12, dirname: dirname6 } = require("path");
|
|
1324
1513
|
const home = process.env.HOME || process.env.USERPROFILE || "/tmp";
|
|
1325
1514
|
const xdgData = process.env.XDG_DATA_HOME || join12(home, ".local", "share");
|
|
1326
1515
|
const defaultPath = join12(xdgData, "agent_gate", "agent_gate_ts.db");
|
|
1327
1516
|
const path11 = dbPath || defaultPath;
|
|
1328
|
-
const dir2 =
|
|
1517
|
+
const dir2 = dirname6(path11);
|
|
1329
1518
|
if (!existsSync12(dir2)) mkdirSync5(dir2, { recursive: true });
|
|
1330
1519
|
rawDb = new Database(path11);
|
|
1331
1520
|
rawDb.pragma("journal_mode = WAL");
|
|
@@ -1381,15 +1570,29 @@ function sessionHistoryLimit() {
|
|
|
1381
1570
|
const v = Number.isFinite(n) ? n : DEFAULT_MAX_SESSIONS;
|
|
1382
1571
|
return Math.max(1, Math.min(v, 50));
|
|
1383
1572
|
}
|
|
1384
|
-
function buildSessionHistory(queryToolCalls2, sessionId) {
|
|
1573
|
+
function buildSessionHistory(queryToolCalls2, sessionId, listAgentTypes) {
|
|
1385
1574
|
if (!isMultiSessionEnabled()) return [];
|
|
1386
1575
|
const maxSessions = sessionHistoryLimit();
|
|
1387
1576
|
try {
|
|
1388
1577
|
const scanLimit = Math.max(DEFAULT_HISTORY_LIMIT, maxSessions * DEFAULT_ACTIONS_PER_SESSION);
|
|
1389
|
-
const
|
|
1578
|
+
const agentTypes = listAgentTypes?.() ?? [];
|
|
1579
|
+
let recent;
|
|
1580
|
+
if (agentTypes.length > 1) {
|
|
1581
|
+
const perAgent = Math.max(
|
|
1582
|
+
DEFAULT_ACTIONS_PER_SESSION,
|
|
1583
|
+
Math.floor(DEFAULT_HISTORY_LIMIT / agentTypes.length)
|
|
1584
|
+
);
|
|
1585
|
+
recent = agentTypes.flatMap((a) => queryToolCalls2({ limit: perAgent, agentType: a }));
|
|
1586
|
+
} else {
|
|
1587
|
+
recent = queryToolCalls2({ limit: scanLimit });
|
|
1588
|
+
}
|
|
1390
1589
|
const bySession = /* @__PURE__ */ new Map();
|
|
1590
|
+
const sessionAgent = /* @__PURE__ */ new Map();
|
|
1391
1591
|
for (const tc of recent) {
|
|
1392
1592
|
if (tc.session_id === sessionId) continue;
|
|
1593
|
+
if (tc.agent_type && !sessionAgent.has(tc.session_id)) {
|
|
1594
|
+
sessionAgent.set(tc.session_id, tc.agent_type);
|
|
1595
|
+
}
|
|
1393
1596
|
const list = bySession.get(tc.session_id) || [];
|
|
1394
1597
|
list.unshift({
|
|
1395
1598
|
action_type: tc.action_type,
|
|
@@ -1400,6 +1603,7 @@ function buildSessionHistory(queryToolCalls2, sessionId) {
|
|
|
1400
1603
|
}
|
|
1401
1604
|
return [...bySession.entries()].slice(0, maxSessions).map(([sid, actions]) => ({
|
|
1402
1605
|
session_id: sid,
|
|
1606
|
+
...sessionAgent.get(sid) ? { agent_id: sessionAgent.get(sid) } : {},
|
|
1403
1607
|
action_history: actions.slice(0, DEFAULT_ACTIONS_PER_SESSION)
|
|
1404
1608
|
}));
|
|
1405
1609
|
} catch {
|
|
@@ -1589,6 +1793,8 @@ var init_models = __esm({
|
|
|
1589
1793
|
violated_layers: import_zod.z.array(import_zod.z.string()).default([]),
|
|
1590
1794
|
confidence: import_zod.z.number().int().min(0).max(100).default(100),
|
|
1591
1795
|
analysis_duration_ms: import_zod.z.number().default(0),
|
|
1796
|
+
// 结构化攻击链图(组合式拦截时非空;前端弹窗画图用)
|
|
1797
|
+
violation_graph: import_zod.z.any().nullable().optional(),
|
|
1592
1798
|
oversize: import_zod.z.boolean().optional().describe("\u672C\u5730\u5B58\u50A8\u662F\u5426\u8D85\u8FC7\u6E05\u7406\u9608\u503C\uFF08agg \u7528\uFF09"),
|
|
1593
1799
|
thresholdMB: import_zod.z.number().optional().describe("\u5B58\u50A8\u6E05\u7406\u9608\u503C MB\uFF08agg \u7528\uFF09"),
|
|
1594
1800
|
collected_context: import_zod.z.object({
|
|
@@ -1905,7 +2111,9 @@ async function analyzeRoute(c) {
|
|
|
1905
2111
|
if (isMultiSessionEnabled()) {
|
|
1906
2112
|
input.session_history = buildSessionHistory(
|
|
1907
2113
|
(params) => queryToolCalls(params),
|
|
1908
|
-
input.session_id
|
|
2114
|
+
input.session_id,
|
|
2115
|
+
// 多 agent 时按 agent 分组取历史,避免高频 agent 把别人的动作挤出窗口
|
|
2116
|
+
() => getAgentsList().map((a) => a.agent_type)
|
|
1909
2117
|
);
|
|
1910
2118
|
}
|
|
1911
2119
|
const mossRequest = normalize(input, context);
|
|
@@ -1931,7 +2139,9 @@ async function analyzeRoute(c) {
|
|
|
1931
2139
|
violated_layers: JSON.stringify(mossResult.violated_layers),
|
|
1932
2140
|
reason: mossResult.reason,
|
|
1933
2141
|
confidence: mossResult.confidence,
|
|
1934
|
-
analysis_duration_ms: performance.now() - t0
|
|
2142
|
+
analysis_duration_ms: performance.now() - t0,
|
|
2143
|
+
// 结构化攻击链图(组合式拦截才有;前端弹窗画图用)
|
|
2144
|
+
violation_graph: JSON.stringify(mossResult.violation_graph || null)
|
|
1935
2145
|
});
|
|
1936
2146
|
setCache(key, mossResult);
|
|
1937
2147
|
if (isMultiSessionEnabled()) {
|
|
@@ -1955,6 +2165,7 @@ async function analyzeRoute(c) {
|
|
|
1955
2165
|
violated_layers: mossResult.violated_layers,
|
|
1956
2166
|
confidence: mossResult.confidence,
|
|
1957
2167
|
analysis_duration_ms: Math.round(durationMs * 10) / 10,
|
|
2168
|
+
violation_graph: mossResult.violation_graph ?? null,
|
|
1958
2169
|
...storageOversizeInfo(),
|
|
1959
2170
|
collected_context: {
|
|
1960
2171
|
os: context.os,
|
|
@@ -2193,9 +2404,9 @@ async function dashboardRoute(c) {
|
|
|
2193
2404
|
}
|
|
2194
2405
|
}
|
|
2195
2406
|
const { readFileSync: readFileSync14, existsSync: existsSync12 } = await import("fs");
|
|
2196
|
-
const { resolve: resolve4, dirname:
|
|
2407
|
+
const { resolve: resolve4, dirname: dirname6 } = await import("path");
|
|
2197
2408
|
const { fileURLToPath } = await import("url");
|
|
2198
|
-
const __dirname2 =
|
|
2409
|
+
const __dirname2 = dirname6(fileURLToPath(importMetaUrl));
|
|
2199
2410
|
const paths = [
|
|
2200
2411
|
resolve4(__dirname2, "dashboard.html"),
|
|
2201
2412
|
resolve4(__dirname2, "../dashboard.html"),
|
|
@@ -6366,7 +6577,7 @@ var require_websocket = __commonJS({
|
|
|
6366
6577
|
var http5 = require("http");
|
|
6367
6578
|
var net2 = require("net");
|
|
6368
6579
|
var tls = require("tls");
|
|
6369
|
-
var { randomBytes: randomBytes2, createHash:
|
|
6580
|
+
var { randomBytes: randomBytes2, createHash: createHash5 } = require("crypto");
|
|
6370
6581
|
var { Duplex, Readable } = require("stream");
|
|
6371
6582
|
var { URL: URL5 } = require("url");
|
|
6372
6583
|
var PerMessageDeflate = require_permessage_deflate();
|
|
@@ -7034,7 +7245,7 @@ var require_websocket = __commonJS({
|
|
|
7034
7245
|
abortHandshake(websocket, socket, "Invalid Upgrade header");
|
|
7035
7246
|
return;
|
|
7036
7247
|
}
|
|
7037
|
-
const digest =
|
|
7248
|
+
const digest = createHash5("sha1").update(key + GUID).digest("base64");
|
|
7038
7249
|
if (res.headers["sec-websocket-accept"] !== digest) {
|
|
7039
7250
|
abortHandshake(websocket, socket, "Invalid Sec-WebSocket-Accept header");
|
|
7040
7251
|
return;
|
|
@@ -7406,7 +7617,7 @@ var require_websocket_server = __commonJS({
|
|
|
7406
7617
|
var EventEmitter2 = require("events");
|
|
7407
7618
|
var http5 = require("http");
|
|
7408
7619
|
var { Duplex } = require("stream");
|
|
7409
|
-
var { createHash:
|
|
7620
|
+
var { createHash: createHash5 } = require("crypto");
|
|
7410
7621
|
var extension = require_extension();
|
|
7411
7622
|
var PerMessageDeflate = require_permessage_deflate();
|
|
7412
7623
|
var subprotocol = require_subprotocol();
|
|
@@ -7713,7 +7924,7 @@ var require_websocket_server = __commonJS({
|
|
|
7713
7924
|
);
|
|
7714
7925
|
}
|
|
7715
7926
|
if (this._state > RUNNING) return abortHandshake(socket, 503);
|
|
7716
|
-
const digest =
|
|
7927
|
+
const digest = createHash5("sha1").update(key + GUID).digest("base64");
|
|
7717
7928
|
const headers = [
|
|
7718
7929
|
"HTTP/1.1 101 Switching Protocols",
|
|
7719
7930
|
"Upgrade: websocket",
|
|
@@ -25894,14 +26105,14 @@ var require_find_made = __commonJS({
|
|
|
25894
26105
|
"../node_modules/mkdirp/lib/find-made.js"(exports2, module2) {
|
|
25895
26106
|
"use strict";
|
|
25896
26107
|
init_cjs_shims();
|
|
25897
|
-
var { dirname:
|
|
26108
|
+
var { dirname: dirname6 } = require("path");
|
|
25898
26109
|
var findMade = (opts, parent2, path11 = void 0) => {
|
|
25899
26110
|
if (path11 === parent2)
|
|
25900
26111
|
return Promise.resolve();
|
|
25901
26112
|
return opts.statAsync(parent2).then(
|
|
25902
26113
|
(st) => st.isDirectory() ? path11 : void 0,
|
|
25903
26114
|
// will fail later
|
|
25904
|
-
(er) => er.code === "ENOENT" ? findMade(opts,
|
|
26115
|
+
(er) => er.code === "ENOENT" ? findMade(opts, dirname6(parent2), parent2) : void 0
|
|
25905
26116
|
);
|
|
25906
26117
|
};
|
|
25907
26118
|
var findMadeSync = (opts, parent2, path11 = void 0) => {
|
|
@@ -25910,7 +26121,7 @@ var require_find_made = __commonJS({
|
|
|
25910
26121
|
try {
|
|
25911
26122
|
return opts.statSync(parent2).isDirectory() ? path11 : void 0;
|
|
25912
26123
|
} catch (er) {
|
|
25913
|
-
return er.code === "ENOENT" ? findMadeSync(opts,
|
|
26124
|
+
return er.code === "ENOENT" ? findMadeSync(opts, dirname6(parent2), parent2) : void 0;
|
|
25914
26125
|
}
|
|
25915
26126
|
};
|
|
25916
26127
|
module2.exports = { findMade, findMadeSync };
|
|
@@ -25922,10 +26133,10 @@ var require_mkdirp_manual = __commonJS({
|
|
|
25922
26133
|
"../node_modules/mkdirp/lib/mkdirp-manual.js"(exports2, module2) {
|
|
25923
26134
|
"use strict";
|
|
25924
26135
|
init_cjs_shims();
|
|
25925
|
-
var { dirname:
|
|
26136
|
+
var { dirname: dirname6 } = require("path");
|
|
25926
26137
|
var mkdirpManual = (path11, opts, made) => {
|
|
25927
26138
|
opts.recursive = false;
|
|
25928
|
-
const parent2 =
|
|
26139
|
+
const parent2 = dirname6(path11);
|
|
25929
26140
|
if (parent2 === path11) {
|
|
25930
26141
|
return opts.mkdirAsync(path11, opts).catch((er) => {
|
|
25931
26142
|
if (er.code !== "EISDIR")
|
|
@@ -25948,7 +26159,7 @@ var require_mkdirp_manual = __commonJS({
|
|
|
25948
26159
|
});
|
|
25949
26160
|
};
|
|
25950
26161
|
var mkdirpManualSync = (path11, opts, made) => {
|
|
25951
|
-
const parent2 =
|
|
26162
|
+
const parent2 = dirname6(path11);
|
|
25952
26163
|
opts.recursive = false;
|
|
25953
26164
|
if (parent2 === path11) {
|
|
25954
26165
|
try {
|
|
@@ -25985,12 +26196,12 @@ var require_mkdirp_native = __commonJS({
|
|
|
25985
26196
|
"../node_modules/mkdirp/lib/mkdirp-native.js"(exports2, module2) {
|
|
25986
26197
|
"use strict";
|
|
25987
26198
|
init_cjs_shims();
|
|
25988
|
-
var { dirname:
|
|
26199
|
+
var { dirname: dirname6 } = require("path");
|
|
25989
26200
|
var { findMade, findMadeSync } = require_find_made();
|
|
25990
26201
|
var { mkdirpManual, mkdirpManualSync } = require_mkdirp_manual();
|
|
25991
26202
|
var mkdirpNative = (path11, opts) => {
|
|
25992
26203
|
opts.recursive = true;
|
|
25993
|
-
const parent2 =
|
|
26204
|
+
const parent2 = dirname6(path11);
|
|
25994
26205
|
if (parent2 === path11)
|
|
25995
26206
|
return opts.mkdirAsync(path11, opts);
|
|
25996
26207
|
return findMade(opts, path11).then((made) => opts.mkdirAsync(path11, opts).then(() => made).catch((er) => {
|
|
@@ -26002,7 +26213,7 @@ var require_mkdirp_native = __commonJS({
|
|
|
26002
26213
|
};
|
|
26003
26214
|
var mkdirpNativeSync = (path11, opts) => {
|
|
26004
26215
|
opts.recursive = true;
|
|
26005
|
-
const parent2 =
|
|
26216
|
+
const parent2 = dirname6(path11);
|
|
26006
26217
|
if (parent2 === path11)
|
|
26007
26218
|
return opts.mkdirSync(path11, opts);
|
|
26008
26219
|
const made = findMadeSync(opts, path11);
|
|
@@ -26458,17 +26669,17 @@ var require_ProxyFinalRequestFilter = __commonJS({
|
|
|
26458
26669
|
// ../node_modules/uuid/dist/esm-node/rng.js
|
|
26459
26670
|
function rng() {
|
|
26460
26671
|
if (poolPtr > rnds8Pool.length - 16) {
|
|
26461
|
-
|
|
26672
|
+
import_crypto2.default.randomFillSync(rnds8Pool);
|
|
26462
26673
|
poolPtr = 0;
|
|
26463
26674
|
}
|
|
26464
26675
|
return rnds8Pool.slice(poolPtr, poolPtr += 16);
|
|
26465
26676
|
}
|
|
26466
|
-
var
|
|
26677
|
+
var import_crypto2, rnds8Pool, poolPtr;
|
|
26467
26678
|
var init_rng = __esm({
|
|
26468
26679
|
"../node_modules/uuid/dist/esm-node/rng.js"() {
|
|
26469
26680
|
"use strict";
|
|
26470
26681
|
init_cjs_shims();
|
|
26471
|
-
|
|
26682
|
+
import_crypto2 = __toESM(require("crypto"));
|
|
26472
26683
|
rnds8Pool = new Uint8Array(256);
|
|
26473
26684
|
poolPtr = rnds8Pool.length;
|
|
26474
26685
|
}
|
|
@@ -26683,14 +26894,14 @@ function md5(bytes) {
|
|
|
26683
26894
|
} else if (typeof bytes === "string") {
|
|
26684
26895
|
bytes = Buffer.from(bytes, "utf8");
|
|
26685
26896
|
}
|
|
26686
|
-
return
|
|
26897
|
+
return import_crypto3.default.createHash("md5").update(bytes).digest();
|
|
26687
26898
|
}
|
|
26688
|
-
var
|
|
26899
|
+
var import_crypto3, md5_default;
|
|
26689
26900
|
var init_md5 = __esm({
|
|
26690
26901
|
"../node_modules/uuid/dist/esm-node/md5.js"() {
|
|
26691
26902
|
"use strict";
|
|
26692
26903
|
init_cjs_shims();
|
|
26693
|
-
|
|
26904
|
+
import_crypto3 = __toESM(require("crypto"));
|
|
26694
26905
|
md5_default = md5;
|
|
26695
26906
|
}
|
|
26696
26907
|
});
|
|
@@ -26709,14 +26920,14 @@ var init_v3 = __esm({
|
|
|
26709
26920
|
});
|
|
26710
26921
|
|
|
26711
26922
|
// ../node_modules/uuid/dist/esm-node/native.js
|
|
26712
|
-
var
|
|
26923
|
+
var import_crypto4, native_default;
|
|
26713
26924
|
var init_native = __esm({
|
|
26714
26925
|
"../node_modules/uuid/dist/esm-node/native.js"() {
|
|
26715
26926
|
"use strict";
|
|
26716
26927
|
init_cjs_shims();
|
|
26717
|
-
|
|
26928
|
+
import_crypto4 = __toESM(require("crypto"));
|
|
26718
26929
|
native_default = {
|
|
26719
|
-
randomUUID:
|
|
26930
|
+
randomUUID: import_crypto4.default.randomUUID
|
|
26720
26931
|
};
|
|
26721
26932
|
}
|
|
26722
26933
|
});
|
|
@@ -26758,14 +26969,14 @@ function sha1(bytes) {
|
|
|
26758
26969
|
} else if (typeof bytes === "string") {
|
|
26759
26970
|
bytes = Buffer.from(bytes, "utf8");
|
|
26760
26971
|
}
|
|
26761
|
-
return
|
|
26972
|
+
return import_crypto5.default.createHash("sha1").update(bytes).digest();
|
|
26762
26973
|
}
|
|
26763
|
-
var
|
|
26974
|
+
var import_crypto5, sha1_default;
|
|
26764
26975
|
var init_sha1 = __esm({
|
|
26765
26976
|
"../node_modules/uuid/dist/esm-node/sha1.js"() {
|
|
26766
26977
|
"use strict";
|
|
26767
26978
|
init_cjs_shims();
|
|
26768
|
-
|
|
26979
|
+
import_crypto5 = __toESM(require("crypto"));
|
|
26769
26980
|
sha1_default = sha1;
|
|
26770
26981
|
}
|
|
26771
26982
|
});
|
|
@@ -29767,24 +29978,11 @@ var init_coordinator = __esm({
|
|
|
29767
29978
|
}
|
|
29768
29979
|
// ── AgentMoss report building ─────────────────────────────────────────────
|
|
29769
29980
|
_buildSessionHistory(sessionId) {
|
|
29770
|
-
|
|
29771
|
-
|
|
29772
|
-
|
|
29773
|
-
|
|
29774
|
-
|
|
29775
|
-
if (tc.session_id === sessionId) continue;
|
|
29776
|
-
const list = bySession.get(tc.session_id) || [];
|
|
29777
|
-
list.unshift({ action_type: tc.action_type, action_detail: tc.action_detail });
|
|
29778
|
-
bySession.set(tc.session_id, list);
|
|
29779
|
-
}
|
|
29780
|
-
const sessions = [...bySession.entries()].slice(0, 5);
|
|
29781
|
-
return sessions.map(([sid, actions]) => ({
|
|
29782
|
-
session_id: sid,
|
|
29783
|
-
action_history: actions.slice(0, 100)
|
|
29784
|
-
}));
|
|
29785
|
-
} catch {
|
|
29786
|
-
return [];
|
|
29787
|
-
}
|
|
29981
|
+
return buildSessionHistory(
|
|
29982
|
+
(params) => queryToolCalls(params),
|
|
29983
|
+
sessionId,
|
|
29984
|
+
() => getAgentsList().map((a) => a.agent_type)
|
|
29985
|
+
);
|
|
29788
29986
|
}
|
|
29789
29987
|
buildMossReport(sessionId, session, event, triggerMatches) {
|
|
29790
29988
|
const actionHistory = [];
|