@aomi-labs/react 0.3.7 → 0.3.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.
package/dist/index.js CHANGED
@@ -882,6 +882,16 @@ import {
882
882
  } from "react";
883
883
  import { jsx as jsx5 } from "react/jsx-runtime";
884
884
  var UserContext = createContext5(void 0);
885
+ function normalizeUserState(next, data) {
886
+ if (data.isConnected === false) {
887
+ return __spreadProps(__spreadValues({}, next), {
888
+ address: void 0,
889
+ chainId: void 0,
890
+ ensName: void 0
891
+ });
892
+ }
893
+ return next;
894
+ }
885
895
  function useUser() {
886
896
  const context = useContext5(UserContext);
887
897
  if (!context) {
@@ -911,7 +921,7 @@ function UserContextProvider({ children }) {
911
921
  );
912
922
  const setUser = useCallback4((data) => {
913
923
  setUserState((prev) => {
914
- const next = __spreadValues(__spreadValues({}, prev), data);
924
+ const next = normalizeUserState(__spreadValues(__spreadValues({}, prev), data), data);
915
925
  StateChangeCallbacks.current.forEach((callback) => {
916
926
  callback(next);
917
927
  });
@@ -1490,7 +1500,7 @@ function AomiRuntimeCore({
1490
1500
  const eventContext = useEventContext();
1491
1501
  const notificationContext = useNotification();
1492
1502
  const { user, onUserStateChange, getUserState } = useUser();
1493
- const { getControlState, getCurrentThreadApp, clearSecrets } = useControl();
1503
+ const { getControlState, getCurrentThreadApp } = useControl();
1494
1504
  const sessionManagerRef = useRef7(null);
1495
1505
  const walletHandler = useWalletHandler({
1496
1506
  getSession: () => {
@@ -1508,7 +1518,11 @@ function AomiRuntimeCore({
1508
1518
  cancelGeneration: orchestratorCancel,
1509
1519
  aomiClientRef
1510
1520
  } = useRuntimeOrchestrator(aomiClient, {
1511
- getPublicKey: () => getUserState().address,
1521
+ getPublicKey: () => {
1522
+ var _a;
1523
+ const userState = getUserState();
1524
+ return userState.isConnected ? (_a = userState.address) != null ? _a : void 0 : void 0;
1525
+ },
1512
1526
  getUserState,
1513
1527
  getApp: getCurrentThreadApp,
1514
1528
  getApiKey: () => getControlState().apiKey,
@@ -1591,7 +1605,7 @@ function AomiRuntimeCore({
1591
1605
  threadContext.currentThreadId
1592
1606
  );
1593
1607
  useEffect3(() => {
1594
- const userAddress = user.address;
1608
+ const userAddress = user.isConnected ? user.address : void 0;
1595
1609
  if (!userAddress) return;
1596
1610
  const fetchThreadList = async () => {
1597
1611
  var _a, _b, _c;
@@ -1628,7 +1642,7 @@ function AomiRuntimeCore({
1628
1642
  }
1629
1643
  };
1630
1644
  void fetchThreadList();
1631
- }, [user.address, aomiClientRef]);
1645
+ }, [user.address, user.isConnected, aomiClientRef]);
1632
1646
  const threadListAdapter = useMemo2(
1633
1647
  () => buildThreadListAdapter({
1634
1648
  aomiClientRef,
@@ -1694,9 +1708,8 @@ function AomiRuntimeCore({
1694
1708
  useEffect3(() => {
1695
1709
  return () => {
1696
1710
  sessionManager.closeAll();
1697
- void clearSecrets();
1698
1711
  };
1699
- }, [sessionManager, clearSecrets]);
1712
+ }, [sessionManager]);
1700
1713
  const userContext = useUser();
1701
1714
  const sendMessage = useCallback7(
1702
1715
  async (text) => {
@@ -1832,7 +1845,7 @@ function AomiRuntimeInner({
1832
1845
  {
1833
1846
  aomiClient,
1834
1847
  sessionId: threadContext.currentThreadId,
1835
- publicKey: (_a = user.address) != null ? _a : void 0,
1848
+ publicKey: user.isConnected ? (_a = user.address) != null ? _a : void 0 : void 0,
1836
1849
  getThreadMetadata: threadContext.getThreadMetadata,
1837
1850
  updateThreadMetadata: threadContext.updateThreadMetadata,
1838
1851
  children: /* @__PURE__ */ jsx7(