@akshar5/cohall 0.12.7 → 0.12.9

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 (31) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +6 -0
  3. package/bin/{chunk-akct7v1q.js → chunk-0d3g10k2.js} +5 -5
  4. package/bin/{chunk-b3ba95j4.js → chunk-1bmb5y87.js} +33 -6
  5. package/bin/{chunk-b3ba95j4.js.map → chunk-1bmb5y87.js.map} +3 -3
  6. package/bin/{chunk-61m7z93m.js → chunk-8kfggcj5.js} +1 -1
  7. package/bin/{chunk-39by7csf.js → chunk-c78ed3xe.js} +4 -4
  8. package/bin/{chunk-90k4bw6t.js → chunk-fgj3e2gh.js} +35 -10
  9. package/bin/chunk-fgj3e2gh.js.map +14 -0
  10. package/bin/{chunk-89ga9j8t.js → chunk-hdh0nnc8.js} +1 -1
  11. package/bin/{chunk-27xa296w.js → chunk-jr6pyy7x.js} +1 -1
  12. package/bin/{chunk-7ss2d5n4.js → chunk-kte3y9sj.js} +2 -2
  13. package/bin/{chunk-d2sykjmx.js → chunk-nhc7emaz.js} +13 -5
  14. package/bin/chunk-nhc7emaz.js.map +10 -0
  15. package/bin/{chunk-7dgeftrk.js → chunk-ym98h2bp.js} +2 -2
  16. package/bin/{chunk-7dgeftrk.js.map → chunk-ym98h2bp.js.map} +1 -1
  17. package/bin/{chunk-zxrjgp9k.js → chunk-zwxzxnsj.js} +1 -1
  18. package/bin/cohall.js +7 -7
  19. package/docs/grok-bot.md +9 -0
  20. package/docs/install.md +6 -0
  21. package/docs/muse.md +13 -9
  22. package/package.json +1 -1
  23. package/bin/chunk-90k4bw6t.js.map +0 -14
  24. package/bin/chunk-d2sykjmx.js.map +0 -10
  25. /package/bin/{chunk-akct7v1q.js.map → chunk-0d3g10k2.js.map} +0 -0
  26. /package/bin/{chunk-61m7z93m.js.map → chunk-8kfggcj5.js.map} +0 -0
  27. /package/bin/{chunk-39by7csf.js.map → chunk-c78ed3xe.js.map} +0 -0
  28. /package/bin/{chunk-89ga9j8t.js.map → chunk-hdh0nnc8.js.map} +0 -0
  29. /package/bin/{chunk-27xa296w.js.map → chunk-jr6pyy7x.js.map} +0 -0
  30. /package/bin/{chunk-7ss2d5n4.js.map → chunk-kte3y9sj.js.map} +0 -0
  31. /package/bin/{chunk-zxrjgp9k.js.map → chunk-zwxzxnsj.js.map} +0 -0
@@ -65,7 +65,7 @@ import {
65
65
  import {
66
66
  __export,
67
67
  version
68
- } from "./chunk-7dgeftrk.js";
68
+ } from "./chunk-ym98h2bp.js";
69
69
 
70
70
  // apps/relay/src/main.ts
71
71
  import { Effect as Effect3, ManagedRuntime, Schema as Schema3, Schedule } from "effect";
@@ -199,6 +199,15 @@ class Hub {
199
199
  boundDeviceId(socket) {
200
200
  return this.#principals.get(socket)?.boundDeviceId;
201
201
  }
202
+ sessionId(socket) {
203
+ return this.#principals.get(socket)?.sessionId;
204
+ }
205
+ updateSessionExpiry(socket, expiresAt) {
206
+ const principal = this.#principals.get(socket);
207
+ if (principal !== undefined) {
208
+ this.#principals.set(socket, { ...principal, expiresAt });
209
+ }
210
+ }
202
211
  registerDevice(deviceId, socket) {
203
212
  if (this.#deviceIds.has(socket)) {
204
213
  return false;
@@ -1622,9 +1631,10 @@ var makeService = (db, retainedTerminalTasks = 1000) => {
1622
1631
  });
1623
1632
  return PairingCredential.make({ token, expiresAt: Timestamp.make(expiresAt) });
1624
1633
  });
1634
+ const sessionLifetimeMs = 90 * 24 * 60 * 60 * 1000;
1625
1635
  const exchangePairing = Effect2.fn("RelayStore.exchangePairing")(function* (token) {
1626
1636
  const timestamp = now();
1627
- const expiresAt = new Date(Date.now() + 90 * 24 * 60 * 60 * 1000).toISOString();
1637
+ const expiresAt = new Date(Date.parse(timestamp) + sessionLifetimeMs).toISOString();
1628
1638
  const created = yield* Effect2.try({
1629
1639
  try: () => db.transaction(() => {
1630
1640
  const pairing = db.query(`SELECT * FROM auth_pairings
@@ -1663,6 +1673,17 @@ var makeService = (db, retainedTerminalTasks = 1000) => {
1663
1673
  const credentials = yield* Effect2.forEach(created, ({ token: sessionToken, row }) => authSessionFromRow(row).pipe(Effect2.map((session) => ({ token: sessionToken, session }))));
1664
1674
  return PairingResult.make({ credentials });
1665
1675
  });
1676
+ const renewAuthSession = Effect2.fn("RelayStore.renewAuthSession")(function* (sessionId) {
1677
+ const timestamp = now();
1678
+ const expiresAt = new Date(Date.parse(timestamp) + sessionLifetimeMs).toISOString();
1679
+ const row = yield* Effect2.try({
1680
+ try: () => db.query(`UPDATE auth_sessions SET last_seen_at = ?, expires_at = ?
1681
+ WHERE id = ? AND revoked_at IS NULL AND expires_at > ?
1682
+ RETURNING *`).get(timestamp, expiresAt, sessionId, timestamp),
1683
+ catch: operationError("RelayStore.renewAuthSession")
1684
+ });
1685
+ return row === null ? undefined : yield* authSessionFromRow(row);
1686
+ });
1666
1687
  const authenticateSession = Effect2.fn("RelayStore.authenticateSession")(function* (token, role) {
1667
1688
  const row = yield* Effect2.try({
1668
1689
  try: () => db.query(`SELECT * FROM auth_sessions
@@ -1672,13 +1693,7 @@ var makeService = (db, retainedTerminalTasks = 1000) => {
1672
1693
  if (row === null || !rolesFromRow(row).includes(role)) {
1673
1694
  return;
1674
1695
  }
1675
- const lastSeenAt = now();
1676
- yield* Effect2.try({
1677
- try: () => db.query("UPDATE auth_sessions SET last_seen_at = ? WHERE id = ?").run(lastSeenAt, row.id),
1678
- catch: operationError("RelayStore.authenticateSession.touch")
1679
- });
1680
- const session = yield* authSessionFromRow(row);
1681
- return AuthSession.make({ ...session, lastSeenAt });
1696
+ return yield* renewAuthSession(AuthSessionId.make(row.id));
1682
1697
  });
1683
1698
  const listAuthSessions = Effect2.fn("RelayStore.listAuthSessions")(function* () {
1684
1699
  const rows = yield* Effect2.try({
@@ -1764,6 +1779,7 @@ var makeService = (db, retainedTerminalTasks = 1000) => {
1764
1779
  createPairing,
1765
1780
  exchangePairing,
1766
1781
  authenticateSession,
1782
+ renewAuthSession,
1767
1783
  listAuthSessions,
1768
1784
  revokeAuthSession
1769
1785
  });
@@ -2368,6 +2384,15 @@ var runRelay = async () => {
2368
2384
  switch (event._tag) {
2369
2385
  case "DeviceHeartbeat":
2370
2386
  if (event.deviceId === deviceId) {
2387
+ const sessionId = hub.sessionId(socket);
2388
+ if (sessionId !== undefined) {
2389
+ const session = yield* store.renewAuthSession(sessionId);
2390
+ if (session === undefined) {
2391
+ socket.close(4003, "Session expired or revoked");
2392
+ return;
2393
+ }
2394
+ hub.updateSessionExpiry(socket, session.expiresAt);
2395
+ }
2371
2396
  yield* store.heartbeat(deviceId, event.status === "busy" ? "busy" : "online", event.bots);
2372
2397
  }
2373
2398
  return;
@@ -2798,4 +2823,4 @@ export {
2798
2823
  canDispatchTaskToDevice
2799
2824
  };
2800
2825
 
2801
- //# debugId=EDED4526FC76EFE964756E2164756E21
2826
+ //# debugId=733B03E4713AC74F64756E2164756E21