@productbrain/mcp 0.0.1-beta.10898 → 0.0.1-beta.10908

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.
@@ -821,14 +821,12 @@ function kernelCallErrorFrom(fn, status, body) {
821
821
  }
822
822
  var MAX_RATE_LIMIT_RETRY_WAIT_SECONDS = 60;
823
823
  var NO_RATE_LIMIT_RETRY_ROUTES = /* @__PURE__ */ new Set([
824
- "agent.touchSession",
825
824
  "agent.recordActivity",
826
825
  "gaps.record",
827
826
  "gaps.resolve",
828
827
  "chain.recordBriefRun",
829
828
  "agent.reportOrientMetric",
830
- "chain.recordSessionSignal",
831
- "chain.recordGroundingOutcome"
829
+ "chain.recordSessionSignal"
832
830
  ]);
833
831
  async function withOneRateLimitRetry(fn, attempt) {
834
832
  if (NO_RATE_LIMIT_RETRY_ROUTES.has(fn)) return attempt();
@@ -1548,17 +1546,14 @@ async function orphanAgentSession() {
1548
1546
  }
1549
1547
  var _lastTouchAtBySession = /* @__PURE__ */ new Map();
1550
1548
  var TOUCH_THROTTLE_MS = 5e3;
1551
- function touchSessionActivity() {
1549
+ function sessionTouchHeader(fn) {
1552
1550
  const sessionId = sessionLifecycle().agentSessionId;
1553
- if (!sessionId) return;
1554
- const now = Date.now();
1555
- const lastTouchAt = _lastTouchAtBySession.get(sessionId) ?? 0;
1556
- if (now - lastTouchAt < TOUCH_THROTTLE_MS) return;
1557
- _lastTouchAtBySession.set(sessionId, now);
1558
- kernelCall("agent.touchSession", {
1559
- sessionId
1560
- }).catch(() => {
1561
- });
1551
+ const prior = sessionId ? _lastTouchAtBySession.get(sessionId) : void 0;
1552
+ if (!sessionId || TOUCH_EXCLUDED.has(fn) || Date.now() - (prior ?? 0) < TOUCH_THROTTLE_MS) return { headers: {}, release: () => {
1553
+ } };
1554
+ _lastTouchAtBySession.set(sessionId, Date.now());
1555
+ const release = () => prior === void 0 ? _lastTouchAtBySession.delete(sessionId) : _lastTouchAtBySession.set(sessionId, prior);
1556
+ return { headers: { "x-pb-session": sessionId }, release };
1562
1557
  }
1563
1558
  function resetTouchThrottle(sessionId) {
1564
1559
  if (sessionId) {
@@ -1646,6 +1641,7 @@ async function callGateway(fn, args) {
1646
1641
  const apiKey = getActiveApiKey();
1647
1642
  const budgetMs = latencyBudgetMsForRoute(fn);
1648
1643
  const start = Date.now();
1644
+ const touch = sessionTouchHeader(fn);
1649
1645
  let res;
1650
1646
  try {
1651
1647
  res = await fetch(`${siteUrl}/api/aki`, {
@@ -1657,8 +1653,10 @@ async function callGateway(fn, args) {
1657
1653
  // DEC-1207: attribute this connector for the gateway's context.served seam. MCP is
1658
1654
  // the dominant agent surface (INS-1706); without this header it was emitting nothing.
1659
1655
  "x-pb-source": MCP_TELEMETRY_SOURCE,
1660
- ...commandHeader()
1656
+ ...commandHeader(),
1661
1657
  // TASK-893: x-pb-command, the tool call this request serves
1658
+ ...touch.headers
1659
+ // TASK-894: the heartbeat rides the request
1662
1660
  },
1663
1661
  body: JSON.stringify({ fn, args })
1664
1662
  });
@@ -1691,6 +1689,7 @@ async function callGateway(fn, args) {
1691
1689
  const errJson = json;
1692
1690
  const msg = errJson.error ?? errJson.message ?? "unknown error";
1693
1691
  audit(fn, "error", Date.now() - start, errJson.code ? `${msg} [${errJson.code}]` : msg, { budgetMs });
1692
+ if (res.status === 429) touch.release();
1694
1693
  throw kernelCallErrorFrom(fn, res.status, errJson);
1695
1694
  }
1696
1695
  audit(fn, "ok", Date.now() - start, void 0, { budgetMs });
@@ -1713,16 +1712,10 @@ async function kernelCall(fn, args = {}) {
1713
1712
  } else {
1714
1713
  setCached(fn, args, data);
1715
1714
  }
1716
- if (getAgentSessionId() && !TOUCH_EXCLUDED.has(fn)) {
1717
- touchSessionActivity();
1718
- }
1719
1715
  return data;
1720
1716
  }
1721
1717
  async function kernelCallEnvelope(fn, args = {}) {
1722
1718
  const { data, summary, next, _meta } = await withOneRateLimitRetry(fn, () => callGateway(fn, args));
1723
- if (getAgentSessionId() && !TOUCH_EXCLUDED.has(fn)) {
1724
- touchSessionActivity();
1725
- }
1726
1719
  return { ok: true, summary, data, next, _meta };
1727
1720
  }
1728
1721
  var resolveInFlightMap = /* @__PURE__ */ new Map();
@@ -1946,4 +1939,4 @@ export {
1946
1939
  appUrl,
1947
1940
  apiKeysUrl
1948
1941
  };
1949
- //# sourceMappingURL=chunk-GX5RQVW2.js.map
1942
+ //# sourceMappingURL=chunk-KKEKGR2H.js.map