@kenhkl/agent-gate 0.9.11 → 0.9.13

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/v1/cli.js CHANGED
@@ -1693,6 +1693,8 @@ __export(moss_client_exports, {
1693
1693
  callAgentMoss: () => callAgentMoss,
1694
1694
  callAgentMossReview: () => callAgentMossReview,
1695
1695
  fetchMossHealth: () => fetchMossHealth,
1696
+ logDegraded: () => logDegraded,
1697
+ resetDegradedThrottleForTests: () => resetDegradedThrottleForTests,
1696
1698
  setMossUrl: () => setMossUrl
1697
1699
  });
1698
1700
  function authHeaders() {
@@ -1701,6 +1703,19 @@ function authHeaders() {
1701
1703
  if (tok) h["Authorization"] = `Bearer ${tok}`;
1702
1704
  return h;
1703
1705
  }
1706
+ function logDegraded(notes) {
1707
+ const now = Date.now();
1708
+ for (const note of notes) {
1709
+ const key = String(note).replace(/\d+/g, "#");
1710
+ const last = DEGRADED_LAST_LOGGED.get(key);
1711
+ if (last !== void 0 && now - last < DEGRADED_LOG_INTERVAL_MS) continue;
1712
+ DEGRADED_LAST_LOGGED.set(key, now);
1713
+ console.warn(`[AgentGate] AgentMoss \u80FD\u529B\u964D\u7EA7: ${note}`);
1714
+ }
1715
+ }
1716
+ function resetDegradedThrottleForTests() {
1717
+ DEGRADED_LAST_LOGGED.clear();
1718
+ }
1704
1719
  function setMossUrl(url) {
1705
1720
  mossUrl = url;
1706
1721
  }
@@ -1731,7 +1746,12 @@ async function callAgentMoss(request) {
1731
1746
  console.error(`[AgentGate] AgentMoss HTTP ${resp.status}: ${resp.statusText}`);
1732
1747
  return failClosedResponse(`AgentMoss returned ${resp.status}`);
1733
1748
  }
1734
- return await resp.json();
1749
+ const result = await resp.json();
1750
+ const degraded = result?.degraded ?? [];
1751
+ if (degraded.length) {
1752
+ logDegraded(degraded);
1753
+ }
1754
+ return result;
1735
1755
  } catch (err) {
1736
1756
  const errType = err?.type || "";
1737
1757
  const errMsg = String(err?.message || err);
@@ -1787,7 +1807,7 @@ function failClosedResponse(reason, riskType = "service_unavailable") {
1787
1807
  confidence: 100
1788
1808
  };
1789
1809
  }
1790
- var import_node_fetch, DEFAULT_MOSS_URL, mossUrl;
1810
+ var import_node_fetch, DEFAULT_MOSS_URL, DEGRADED_LAST_LOGGED, DEGRADED_LOG_INTERVAL_MS, mossUrl;
1791
1811
  var init_moss_client = __esm({
1792
1812
  "src/shared/moss-client.ts"() {
1793
1813
  "use strict";
@@ -1796,6 +1816,8 @@ var init_moss_client = __esm({
1796
1816
  init_multi_session();
1797
1817
  init_security();
1798
1818
  DEFAULT_MOSS_URL = "http://127.0.0.1:9090";
1819
+ DEGRADED_LAST_LOGGED = /* @__PURE__ */ new Map();
1820
+ DEGRADED_LOG_INTERVAL_MS = 3e5;
1799
1821
  mossUrl = process.env.AGENT_MOSS_URL || process.env.MOSS_URL || DEFAULT_MOSS_URL;
1800
1822
  }
1801
1823
  });
@@ -1806,7 +1828,7 @@ var init_version = __esm({
1806
1828
  "src/version.ts"() {
1807
1829
  "use strict";
1808
1830
  init_cjs_shims();
1809
- _version = true ? "0.9.11" : (() => {
1831
+ _version = true ? "0.9.13" : (() => {
1810
1832
  try {
1811
1833
  const require2 = createRequire(importMetaUrl);
1812
1834
  const pkg = require2("../package.json");
@@ -1885,6 +1907,11 @@ var init_models = __esm({
1885
1907
  violation_graph: import_zod.z.any().nullable().optional(),
1886
1908
  /** 命中的策略/性质描述(与 Python 版响应字段对齐) */
1887
1909
  policy: import_zod.z.string().default(""),
1910
+ /**
1911
+ * 能力降级/预警说明(2026-11):**透传**自 AgentMoss。空数组 = 全部检测层
1912
+ * 完整完成;非空 = 某层没跑全或即将失效,调用方应记录/展示/上报。
1913
+ */
1914
+ degraded: import_zod.z.array(import_zod.z.string()).default([]),
1888
1915
  /** 判定来源:agent_moss / cache(与 Python 版对齐) */
1889
1916
  source: import_zod.z.string().default("agent_moss"),
1890
1917
  oversize: import_zod.z.boolean().optional().describe("\u672C\u5730\u5B58\u50A8\u662F\u5426\u8D85\u8FC7\u6E05\u7406\u9608\u503C\uFF08agg \u7528\uFF09"),
@@ -2873,6 +2900,8 @@ async function analyzeRoute(c) {
2873
2900
  violation_graph: mossResult.violation_graph ?? null,
2874
2901
  // 与 Python 版响应字段对齐(policy / source)
2875
2902
  policy: mossResult.policy ?? "",
2903
+ // 能力降级/预警:**透传**给调用方(客户的 agent),不要吞掉
2904
+ degraded: mossResult.degraded ?? [],
2876
2905
  source: "agent_moss",
2877
2906
  ...storageOversizeInfo(),
2878
2907
  collected_context: {
package/dist/v1/server.js CHANGED
@@ -583,6 +583,8 @@ __export(moss_client_exports, {
583
583
  callAgentMoss: () => callAgentMoss,
584
584
  callAgentMossReview: () => callAgentMossReview,
585
585
  fetchMossHealth: () => fetchMossHealth,
586
+ logDegraded: () => logDegraded,
587
+ resetDegradedThrottleForTests: () => resetDegradedThrottleForTests,
586
588
  setMossUrl: () => setMossUrl
587
589
  });
588
590
  function authHeaders() {
@@ -591,6 +593,19 @@ function authHeaders() {
591
593
  if (tok) h["Authorization"] = `Bearer ${tok}`;
592
594
  return h;
593
595
  }
596
+ function logDegraded(notes) {
597
+ const now = Date.now();
598
+ for (const note of notes) {
599
+ const key = String(note).replace(/\d+/g, "#");
600
+ const last = DEGRADED_LAST_LOGGED.get(key);
601
+ if (last !== void 0 && now - last < DEGRADED_LOG_INTERVAL_MS) continue;
602
+ DEGRADED_LAST_LOGGED.set(key, now);
603
+ console.warn(`[AgentGate] AgentMoss \u80FD\u529B\u964D\u7EA7: ${note}`);
604
+ }
605
+ }
606
+ function resetDegradedThrottleForTests() {
607
+ DEGRADED_LAST_LOGGED.clear();
608
+ }
594
609
  function setMossUrl(url) {
595
610
  mossUrl = url;
596
611
  }
@@ -621,7 +636,12 @@ async function callAgentMoss(request) {
621
636
  console.error(`[AgentGate] AgentMoss HTTP ${resp.status}: ${resp.statusText}`);
622
637
  return failClosedResponse(`AgentMoss returned ${resp.status}`);
623
638
  }
624
- return await resp.json();
639
+ const result = await resp.json();
640
+ const degraded = result?.degraded ?? [];
641
+ if (degraded.length) {
642
+ logDegraded(degraded);
643
+ }
644
+ return result;
625
645
  } catch (err) {
626
646
  const errType = err?.type || "";
627
647
  const errMsg = String(err?.message || err);
@@ -677,7 +697,7 @@ function failClosedResponse(reason, riskType = "service_unavailable") {
677
697
  confidence: 100
678
698
  };
679
699
  }
680
- var import_node_fetch, DEFAULT_MOSS_URL, mossUrl;
700
+ var import_node_fetch, DEFAULT_MOSS_URL, DEGRADED_LAST_LOGGED, DEGRADED_LOG_INTERVAL_MS, mossUrl;
681
701
  var init_moss_client = __esm({
682
702
  "src/shared/moss-client.ts"() {
683
703
  "use strict";
@@ -686,6 +706,8 @@ var init_moss_client = __esm({
686
706
  init_multi_session();
687
707
  init_security();
688
708
  DEFAULT_MOSS_URL = "http://127.0.0.1:9090";
709
+ DEGRADED_LAST_LOGGED = /* @__PURE__ */ new Map();
710
+ DEGRADED_LOG_INTERVAL_MS = 3e5;
689
711
  mossUrl = process.env.AGENT_MOSS_URL || process.env.MOSS_URL || DEFAULT_MOSS_URL;
690
712
  }
691
713
  });
@@ -2274,7 +2296,7 @@ var import_zod = require("zod");
2274
2296
 
2275
2297
  // src/version.ts
2276
2298
  init_cjs_shims();
2277
- var _version = true ? "0.9.11" : (() => {
2299
+ var _version = true ? "0.9.13" : (() => {
2278
2300
  try {
2279
2301
  const require2 = createRequire(importMetaUrl);
2280
2302
  const pkg = require2("../package.json");
@@ -2344,6 +2366,11 @@ var AgentGateResponseSchema = import_zod.z.object({
2344
2366
  violation_graph: import_zod.z.any().nullable().optional(),
2345
2367
  /** 命中的策略/性质描述(与 Python 版响应字段对齐) */
2346
2368
  policy: import_zod.z.string().default(""),
2369
+ /**
2370
+ * 能力降级/预警说明(2026-11):**透传**自 AgentMoss。空数组 = 全部检测层
2371
+ * 完整完成;非空 = 某层没跑全或即将失效,调用方应记录/展示/上报。
2372
+ */
2373
+ degraded: import_zod.z.array(import_zod.z.string()).default([]),
2347
2374
  /** 判定来源:agent_moss / cache(与 Python 版对齐) */
2348
2375
  source: import_zod.z.string().default("agent_moss"),
2349
2376
  oversize: import_zod.z.boolean().optional().describe("\u672C\u5730\u5B58\u50A8\u662F\u5426\u8D85\u8FC7\u6E05\u7406\u9608\u503C\uFF08agg \u7528\uFF09"),
@@ -2696,6 +2723,8 @@ async function analyzeRoute(c) {
2696
2723
  violation_graph: mossResult.violation_graph ?? null,
2697
2724
  // 与 Python 版响应字段对齐(policy / source)
2698
2725
  policy: mossResult.policy ?? "",
2726
+ // 能力降级/预警:**透传**给调用方(客户的 agent),不要吞掉
2727
+ degraded: mossResult.degraded ?? [],
2699
2728
  source: "agent_moss",
2700
2729
  ...storageOversizeInfo(),
2701
2730
  collected_context: {
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.11" : (() => {
53
+ _version = true ? "0.9.13" : (() => {
54
54
  try {
55
55
  const require2 = createRequire(importMetaUrl);
56
56
  const pkg = require2("../package.json");
@@ -1715,6 +1715,8 @@ __export(moss_client_exports, {
1715
1715
  callAgentMoss: () => callAgentMoss,
1716
1716
  callAgentMossReview: () => callAgentMossReview,
1717
1717
  fetchMossHealth: () => fetchMossHealth,
1718
+ logDegraded: () => logDegraded,
1719
+ resetDegradedThrottleForTests: () => resetDegradedThrottleForTests,
1718
1720
  setMossUrl: () => setMossUrl
1719
1721
  });
1720
1722
  function authHeaders() {
@@ -1723,6 +1725,19 @@ function authHeaders() {
1723
1725
  if (tok) h["Authorization"] = `Bearer ${tok}`;
1724
1726
  return h;
1725
1727
  }
1728
+ function logDegraded(notes) {
1729
+ const now = Date.now();
1730
+ for (const note of notes) {
1731
+ const key = String(note).replace(/\d+/g, "#");
1732
+ const last = DEGRADED_LAST_LOGGED.get(key);
1733
+ if (last !== void 0 && now - last < DEGRADED_LOG_INTERVAL_MS) continue;
1734
+ DEGRADED_LAST_LOGGED.set(key, now);
1735
+ console.warn(`[AgentGate] AgentMoss \u80FD\u529B\u964D\u7EA7: ${note}`);
1736
+ }
1737
+ }
1738
+ function resetDegradedThrottleForTests() {
1739
+ DEGRADED_LAST_LOGGED.clear();
1740
+ }
1726
1741
  function setMossUrl(url) {
1727
1742
  mossUrl = url;
1728
1743
  }
@@ -1753,7 +1768,12 @@ async function callAgentMoss(request3) {
1753
1768
  console.error(`[AgentGate] AgentMoss HTTP ${resp.status}: ${resp.statusText}`);
1754
1769
  return failClosedResponse(`AgentMoss returned ${resp.status}`);
1755
1770
  }
1756
- return await resp.json();
1771
+ const result = await resp.json();
1772
+ const degraded = result?.degraded ?? [];
1773
+ if (degraded.length) {
1774
+ logDegraded(degraded);
1775
+ }
1776
+ return result;
1757
1777
  } catch (err) {
1758
1778
  const errType = err?.type || "";
1759
1779
  const errMsg = String(err?.message || err);
@@ -1809,7 +1829,7 @@ function failClosedResponse(reason, riskType = "service_unavailable") {
1809
1829
  confidence: 100
1810
1830
  };
1811
1831
  }
1812
- var import_node_fetch, DEFAULT_MOSS_URL, mossUrl;
1832
+ var import_node_fetch, DEFAULT_MOSS_URL, DEGRADED_LAST_LOGGED, DEGRADED_LOG_INTERVAL_MS, mossUrl;
1813
1833
  var init_moss_client = __esm({
1814
1834
  "src/shared/moss-client.ts"() {
1815
1835
  "use strict";
@@ -1818,6 +1838,8 @@ var init_moss_client = __esm({
1818
1838
  init_multi_session();
1819
1839
  init_security();
1820
1840
  DEFAULT_MOSS_URL = "http://127.0.0.1:9090";
1841
+ DEGRADED_LAST_LOGGED = /* @__PURE__ */ new Map();
1842
+ DEGRADED_LOG_INTERVAL_MS = 3e5;
1821
1843
  mossUrl = process.env.AGENT_MOSS_URL || process.env.MOSS_URL || DEFAULT_MOSS_URL;
1822
1844
  }
1823
1845
  });
@@ -1888,6 +1910,11 @@ var init_models = __esm({
1888
1910
  violation_graph: import_zod.z.any().nullable().optional(),
1889
1911
  /** 命中的策略/性质描述(与 Python 版响应字段对齐) */
1890
1912
  policy: import_zod.z.string().default(""),
1913
+ /**
1914
+ * 能力降级/预警说明(2026-11):**透传**自 AgentMoss。空数组 = 全部检测层
1915
+ * 完整完成;非空 = 某层没跑全或即将失效,调用方应记录/展示/上报。
1916
+ */
1917
+ degraded: import_zod.z.array(import_zod.z.string()).default([]),
1891
1918
  /** 判定来源:agent_moss / cache(与 Python 版对齐) */
1892
1919
  source: import_zod.z.string().default("agent_moss"),
1893
1920
  oversize: import_zod.z.boolean().optional().describe("\u672C\u5730\u5B58\u50A8\u662F\u5426\u8D85\u8FC7\u6E05\u7406\u9608\u503C\uFF08agg \u7528\uFF09"),
@@ -2877,6 +2904,8 @@ async function analyzeRoute(c) {
2877
2904
  violation_graph: mossResult.violation_graph ?? null,
2878
2905
  // 与 Python 版响应字段对齐(policy / source)
2879
2906
  policy: mossResult.policy ?? "",
2907
+ // 能力降级/预警:**透传**给调用方(客户的 agent),不要吞掉
2908
+ degraded: mossResult.degraded ?? [],
2880
2909
  source: "agent_moss",
2881
2910
  ...storageOversizeInfo(),
2882
2911
  collected_context: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kenhkl/agent-gate",
3
- "version": "0.9.11",
3
+ "version": "0.9.13",
4
4
  "description": "AI Agent data collection & security analysis gateway (TypeScript)",
5
5
  "main": "dist/v1/server.js",
6
6
  "bin": {