@rine-network/cli 0.11.1 → 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 +43 -2
  2. package/package.json +1 -1
package/dist/main.js CHANGED
@@ -1845,6 +1845,44 @@ function hookLabel(hostname) {
1845
1845
  return hostname.endsWith(".hook.rine.network") ? hostname.slice(0, -18) : hostname;
1846
1846
  }
1847
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
1848
1886
  //#region src/commands/stream.ts
1849
1887
  function emitLifecycle(gOpts, monitor, data) {
1850
1888
  if (gOpts.json) {
@@ -1903,7 +1941,7 @@ function registerStream(program) {
1903
1941
  let url = `${apiUrl}/agents/${agentId}/stream`;
1904
1942
  if (opts.persistent) url += "?persistent=true";
1905
1943
  const heartbeatTimeoutMs = Math.max(Number(opts.heartbeatTimeout) || 70, 10) * 1e3;
1906
- let lastEventId;
1944
+ let lastEventId = loadStreamCursor(configDir, agentId);
1907
1945
  let backoff = 1;
1908
1946
  let attempt = 0;
1909
1947
  let stopped = false;
@@ -1948,7 +1986,10 @@ function registerStream(program) {
1948
1986
  headers,
1949
1987
  onMessage: ({ event, data, id }) => {
1950
1988
  resetHeartbeatTimer();
1951
- if (id) lastEventId = id;
1989
+ if (id) {
1990
+ lastEventId = id;
1991
+ saveStreamCursor(configDir, agentId, id);
1992
+ }
1952
1993
  if (gOpts.json) {
1953
1994
  if (!opts.monitor || event === "message") console.log(JSON.stringify({
1954
1995
  event,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rine-network/cli",
3
- "version": "0.11.1",
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",