@arbidocs/react 0.5.28 → 0.5.30

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.
package/dist/index.js CHANGED
@@ -6283,6 +6283,8 @@ function ArbiWebSocketProvider({
6283
6283
  children
6284
6284
  }) {
6285
6285
  const arbi = useArbi();
6286
+ const arbiRef = useRef(arbi);
6287
+ arbiRef.current = arbi;
6286
6288
  const queryClient = useQueryClient();
6287
6289
  const subscribersRef = useRef(/* @__PURE__ */ new Set());
6288
6290
  const setStatus = useArbiWsStore((s) => s.setStatus);
@@ -6321,10 +6323,10 @@ function ArbiWebSocketProvider({
6321
6323
  else {
6322
6324
  const type = msg.type;
6323
6325
  if (type.startsWith("chat.") || type === "agent_dm_status")
6324
- void applyChatEvent(arbi, queryClient, msg);
6326
+ void applyChatEvent(arbiRef.current, queryClient, msg);
6325
6327
  else if (type.startsWith("call."))
6326
6328
  applyCallEvent(queryClient, msg, {
6327
- me: arbi.isLoggedIn ? arbi.user.identity()?.externalId ?? null : null,
6329
+ me: arbiRef.current.isLoggedIn ? arbiRef.current.user.identity()?.externalId ?? null : null,
6328
6330
  acceptRings: acceptRingsRef.current
6329
6331
  });
6330
6332
  else void applyLiveUpdate(queryClient, msg);
@@ -6350,8 +6352,11 @@ function ArbiWebSocketProvider({
6350
6352
  };
6351
6353
  const start = async () => {
6352
6354
  if (cancelled) return;
6353
- const info = arbi.getConnectionInfo();
6354
- if (!info) return;
6355
+ const info = arbiRef.current.getConnectionInfo();
6356
+ if (!info) {
6357
+ scheduleRestart();
6358
+ return;
6359
+ }
6355
6360
  conn?.close();
6356
6361
  conn = null;
6357
6362
  setStatus("connecting");
@@ -6363,9 +6368,9 @@ function ArbiWebSocketProvider({
6363
6368
  ),
6364
6369
  accessToken: info.accessToken,
6365
6370
  // Resolve the freshest token on every (re)connect so rotation is picked up.
6366
- getAccessToken: () => arbi.getConnectionInfo()?.accessToken ?? null,
6371
+ getAccessToken: () => arbiRef.current.getConnectionInfo()?.accessToken ?? null,
6367
6372
  // A reconnect refused for its token re-logs in silently first.
6368
- refreshAuth: () => arbi.refreshAccess(),
6373
+ refreshAuth: () => arbiRef.current.refreshAccess(),
6369
6374
  onAuthenticated: (message) => onAuthenticatedRef.current?.(message),
6370
6375
  // The session's: a sign-out closes the socket before the server revokes the token.
6371
6376
  signal: info.signal,
@@ -6406,7 +6411,7 @@ function ArbiWebSocketProvider({
6406
6411
  conn?.close();
6407
6412
  reset();
6408
6413
  };
6409
- }, [enabled, arbi, queryClient, setStatus, setEvicted, applyTaskUpdate, applyPresence, reset]);
6414
+ }, [enabled, queryClient, setStatus, setEvicted, applyTaskUpdate, applyPresence, reset]);
6410
6415
  return /* @__PURE__ */ jsx(ArbiWsContext.Provider, { value: context, children });
6411
6416
  }
6412
6417
  function useArbiWebSocket(onMessage) {