@agentvalet/register 0.4.10 → 0.4.11

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.
Files changed (2) hide show
  1. package/dist/index.js +44 -26
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1619,6 +1619,7 @@ function cleanLocally() {
1619
1619
  }
1620
1620
  console.log(chalk11.green(" \u2713 Cleaned CLAUDE.md, .mcp.json, .claude/settings.local.json"));
1621
1621
  }
1622
+ var SSE_READ_TIMEOUT_MS = 25e3;
1622
1623
  async function pollForApproval(apiUrl, revocationToken, timeoutMs) {
1623
1624
  const streamUrl = `${apiUrl}/v1/revoke-request/stream/${revocationToken}`;
1624
1625
  const deadline = Date.now() + timeoutMs;
@@ -1631,47 +1632,64 @@ async function pollForApproval(apiUrl, revocationToken, timeoutMs) {
1631
1632
  }
1632
1633
  }
1633
1634
  function connect() {
1634
- if (Date.now() > deadline) {
1635
+ if (settled || Date.now() > deadline) {
1635
1636
  done("timeout");
1636
1637
  return;
1637
1638
  }
1638
- fetch(streamUrl, { headers: { Accept: "text/event-stream" } }).then(async (res) => {
1639
+ const controller = new AbortController();
1640
+ let readTimer = setTimeout(() => controller.abort(), SSE_READ_TIMEOUT_MS);
1641
+ function resetReadTimer() {
1642
+ clearTimeout(readTimer);
1643
+ readTimer = setTimeout(() => controller.abort(), SSE_READ_TIMEOUT_MS);
1644
+ }
1645
+ fetch(streamUrl, { signal: controller.signal, headers: { Accept: "text/event-stream" } }).then(async (res) => {
1639
1646
  if (!res.ok || !res.body) {
1640
- done("timeout");
1647
+ clearTimeout(readTimer);
1648
+ if (!settled) setTimeout(connect, 3e3);
1641
1649
  return;
1642
1650
  }
1643
1651
  const reader = res.body.getReader();
1644
1652
  const decoder = new TextDecoder();
1645
1653
  let buf = "";
1646
- while (true) {
1647
- const { done: streamDone, value } = await reader.read();
1648
- if (streamDone) break;
1649
- buf += decoder.decode(value, { stream: true });
1650
- const lines = buf.split("\n");
1651
- buf = lines.pop() ?? "";
1652
- for (const line of lines) {
1653
- if (!line.startsWith("data: ")) continue;
1654
- try {
1655
- const evt = JSON.parse(line.slice(6));
1656
- if (evt.status === "approved") {
1657
- done("approved");
1658
- return;
1659
- }
1660
- if (evt.status === "rejected") {
1661
- done("rejected");
1662
- return;
1654
+ try {
1655
+ while (true) {
1656
+ const { done: streamDone, value } = await reader.read();
1657
+ resetReadTimer();
1658
+ if (streamDone) break;
1659
+ buf += decoder.decode(value, { stream: true });
1660
+ const lines = buf.split("\n");
1661
+ buf = lines.pop() ?? "";
1662
+ for (const line of lines) {
1663
+ if (line.startsWith(":")) continue;
1664
+ if (!line.startsWith("data: ")) continue;
1665
+ try {
1666
+ const evt = JSON.parse(line.slice(6));
1667
+ if (evt.status === "approved") {
1668
+ clearTimeout(readTimer);
1669
+ done("approved");
1670
+ return;
1671
+ }
1672
+ if (evt.status === "rejected") {
1673
+ clearTimeout(readTimer);
1674
+ done("rejected");
1675
+ return;
1676
+ }
1677
+ if (evt.status === "timeout") {
1678
+ clearTimeout(readTimer);
1679
+ done("timeout");
1680
+ return;
1681
+ }
1682
+ } catch {
1663
1683
  }
1664
- if (evt.status === "timeout") {
1665
- done("timeout");
1666
- return;
1667
- }
1668
- } catch {
1669
1684
  }
1670
1685
  }
1686
+ } finally {
1687
+ clearTimeout(readTimer);
1671
1688
  }
1672
1689
  if (!settled) setTimeout(connect, 1e3);
1673
1690
  }).catch(() => {
1674
- if (!settled) setTimeout(connect, 2e3);
1691
+ clearTimeout(readTimer);
1692
+ if (!settled) setTimeout(connect, 1e3);
1675
1693
  });
1676
1694
  }
1677
1695
  connect();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentvalet/register",
3
- "version": "0.4.10",
3
+ "version": "0.4.11",
4
4
  "description": "Self-register AI agents with AgentValet",
5
5
  "type": "module",
6
6
  "bin": {