@rine-network/cli 0.11.0 → 0.11.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.
Files changed (2) hide show
  1. package/dist/main.js +47 -7
  2. package/package.json +2 -2
package/dist/main.js CHANGED
@@ -1697,10 +1697,6 @@ async function runRelayLoop(ctx) {
1697
1697
  attempt++;
1698
1698
  let listener;
1699
1699
  try {
1700
- const token = await getOrRefreshToken(configDir, apiUrl, entry, profileName, {
1701
- force: false,
1702
- envToken: process.env.RINE_TOKEN
1703
- });
1704
1700
  const { hostname, control_ws_url: controlWsUrl } = await resolveHook(client, agentId, opts.hook);
1705
1701
  certHandle = hookLabel(hostname);
1706
1702
  lastDeps = await buildIssueCertDeps({
@@ -1724,7 +1720,10 @@ async function runRelayLoop(ctx) {
1724
1720
  const ref = {};
1725
1721
  const tunnel = await connectTunnel({
1726
1722
  controlWsUrl,
1727
- token,
1723
+ token: await getOrRefreshToken(configDir, apiUrl, entry, profileName, {
1724
+ force: false,
1725
+ envToken: process.env.RINE_TOKEN
1726
+ }),
1728
1727
  agentId,
1729
1728
  hostname,
1730
1729
  openLocalPipe: (frame) => {
@@ -1846,6 +1845,44 @@ function hookLabel(hostname) {
1846
1845
  return hostname.endsWith(".hook.rine.network") ? hostname.slice(0, -18) : hostname;
1847
1846
  }
1848
1847
  //#endregion
1848
+ //#region src/commands/stream-cursor.ts
1849
+ function cursorPath(configDir) {
1850
+ return join(configDir, "state", "stream-cursor.json");
1851
+ }
1852
+ function loadCursorMap(configDir) {
1853
+ try {
1854
+ const raw = fs.readFileSync(cursorPath(configDir), "utf-8");
1855
+ const parsed = JSON.parse(raw);
1856
+ return parsed && typeof parsed === "object" ? parsed : {};
1857
+ } catch {
1858
+ return {};
1859
+ }
1860
+ }
1861
+ /** Return the last persisted event id for an agent, or undefined if none/unreadable. */
1862
+ function loadStreamCursor(configDir, agentId) {
1863
+ const value = loadCursorMap(configDir)[agentId];
1864
+ return typeof value === "string" && value.length > 0 ? value : void 0;
1865
+ }
1866
+ /** Persist the last-seen event id for an agent (best-effort, atomic, no-op if unchanged). */
1867
+ function saveStreamCursor(configDir, agentId, eventId) {
1868
+ if (!eventId) return;
1869
+ try {
1870
+ const map = loadCursorMap(configDir);
1871
+ if (map[agentId] === eventId) return;
1872
+ map[agentId] = eventId;
1873
+ const dir = join(configDir, "state");
1874
+ fs.mkdirSync(dir, {
1875
+ recursive: true,
1876
+ mode: 448
1877
+ });
1878
+ const path = cursorPath(configDir);
1879
+ const tmp = `${path}.tmp`;
1880
+ fs.writeFileSync(tmp, JSON.stringify(map), "utf-8");
1881
+ fs.renameSync(tmp, path);
1882
+ fs.chmodSync(path, 384);
1883
+ } catch {}
1884
+ }
1885
+ //#endregion
1849
1886
  //#region src/commands/stream.ts
1850
1887
  function emitLifecycle(gOpts, monitor, data) {
1851
1888
  if (gOpts.json) {
@@ -1904,7 +1941,7 @@ function registerStream(program) {
1904
1941
  let url = `${apiUrl}/agents/${agentId}/stream`;
1905
1942
  if (opts.persistent) url += "?persistent=true";
1906
1943
  const heartbeatTimeoutMs = Math.max(Number(opts.heartbeatTimeout) || 70, 10) * 1e3;
1907
- let lastEventId;
1944
+ let lastEventId = loadStreamCursor(configDir, agentId);
1908
1945
  let backoff = 1;
1909
1946
  let attempt = 0;
1910
1947
  let stopped = false;
@@ -1949,7 +1986,10 @@ function registerStream(program) {
1949
1986
  headers,
1950
1987
  onMessage: ({ event, data, id }) => {
1951
1988
  resetHeartbeatTimer();
1952
- if (id) lastEventId = id;
1989
+ if (id) {
1990
+ lastEventId = id;
1991
+ saveStreamCursor(configDir, agentId, id);
1992
+ }
1953
1993
  if (gOpts.json) {
1954
1994
  if (!opts.monitor || event === "message") console.log(JSON.stringify({
1955
1995
  event,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rine-network/cli",
3
- "version": "0.11.0",
3
+ "version": "0.11.2",
4
4
  "description": "CLI client for rine.network \u2014 EU-first messaging infrastructure for AI agents",
5
5
  "author": "mmmbs <mmmbs@proton.me>",
6
6
  "license": "EUPL-1.2",
@@ -28,7 +28,7 @@
28
28
  "dev": "tsx src/main.ts"
29
29
  },
30
30
  "dependencies": {
31
- "@rine-network/core": "^0.6.0",
31
+ "@rine-network/core": "^0.6.1",
32
32
  "commander": "^12.0.0",
33
33
  "eventsource-client": "^1.1.0"
34
34
  },