@aomi-labs/react 0.3.11 → 0.3.13

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.cjs CHANGED
@@ -50,20 +50,28 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
50
50
  // packages/react/src/index.ts
51
51
  var index_exports = {};
52
52
  __export(index_exports, {
53
- AomiClient: () => import_client6.AomiClient,
53
+ AomiClient: () => import_client7.AomiClient,
54
54
  AomiRuntimeProvider: () => AomiRuntimeProvider,
55
55
  ControlContextProvider: () => ControlContextProvider,
56
+ DISABLED_PROVIDER_STATE: () => import_client8.DISABLED_PROVIDER_STATE,
56
57
  EventContextProvider: () => EventContextProvider,
57
58
  NotificationContextProvider: () => NotificationContextProvider,
59
+ RuntimeUserStateProvider: () => RuntimeUserStateProvider,
58
60
  SUPPORTED_CHAINS: () => SUPPORTED_CHAINS,
59
61
  ThreadContextProvider: () => ThreadContextProvider,
60
62
  UserContextProvider: () => UserContextProvider,
63
+ aaModeFromExecutionKind: () => import_client8.aaModeFromExecutionKind,
61
64
  cn: () => cn,
65
+ executeWalletCalls: () => import_client8.executeWalletCalls,
62
66
  formatAddress: () => formatAddress,
63
67
  getChainInfo: () => getChainInfo,
64
68
  getNetworkName: () => getNetworkName,
69
+ hydrateTxPayloadFromUserState: () => import_client8.hydrateTxPayloadFromUserState,
65
70
  initThreadControl: () => initThreadControl,
66
- toViemSignTypedDataArgs: () => import_client7.toViemSignTypedDataArgs,
71
+ parseChainId: () => import_client8.parseChainId,
72
+ toAAWalletCall: () => import_client8.toAAWalletCall,
73
+ toAAWalletCalls: () => import_client8.toAAWalletCalls,
74
+ toViemSignTypedDataArgs: () => import_client8.toViemSignTypedDataArgs,
67
75
  useAomiRuntime: () => useAomiRuntime,
68
76
  useControl: () => useControl,
69
77
  useCurrentThreadMessages: () => useCurrentThreadMessages,
@@ -76,12 +84,12 @@ __export(index_exports, {
76
84
  useWalletHandler: () => useWalletHandler
77
85
  });
78
86
  module.exports = __toCommonJS(index_exports);
79
- var import_client6 = require("@aomi-labs/client");
80
87
  var import_client7 = require("@aomi-labs/client");
88
+ var import_client8 = require("@aomi-labs/client");
81
89
 
82
90
  // packages/react/src/runtime/aomi-runtime.tsx
83
- var import_react11 = require("react");
84
- var import_client5 = require("@aomi-labs/client");
91
+ var import_react12 = require("react");
92
+ var import_client6 = require("@aomi-labs/client");
85
93
 
86
94
  // packages/react/src/contexts/control-context.tsx
87
95
  var import_react = require("react");
@@ -926,30 +934,46 @@ function UserContextProvider({ children }) {
926
934
  const StateChangeCallbacks = (0, import_react5.useRef)(
927
935
  /* @__PURE__ */ new Set()
928
936
  );
937
+ const notifyStateChange = (0, import_react5.useCallback)((next) => {
938
+ queueMicrotask(() => {
939
+ StateChangeCallbacks.current.forEach((callback) => {
940
+ callback(next);
941
+ });
942
+ });
943
+ }, []);
944
+ const pruneUndefined = (0, import_react5.useCallback)((state) => {
945
+ return Object.fromEntries(
946
+ Object.entries(state).filter(([, value]) => value !== void 0)
947
+ );
948
+ }, []);
929
949
  const setUser = (0, import_react5.useCallback)((data) => {
930
950
  setUserState((prev) => {
931
951
  var _a, _b, _c;
932
- const normalizedData = (_a = import_client.UserState.normalize(data)) != null ? _a : {};
933
- const next = normalizedData.is_connected === false ? __spreadProps(__spreadValues({}, (_b = import_client.UserState.normalize(__spreadValues(__spreadValues({}, prev), normalizedData))) != null ? _b : prev), {
952
+ const normalizedData = pruneUndefined((_a = import_client.UserState.normalize(data)) != null ? _a : {});
953
+ const nextPartial = __spreadValues({}, normalizedData);
954
+ if (nextPartial.is_connected === true && nextPartial.chain_id === void 0) {
955
+ if (prev.chain_id !== void 0) {
956
+ nextPartial.chain_id = prev.chain_id;
957
+ } else {
958
+ delete nextPartial.is_connected;
959
+ }
960
+ }
961
+ const next = nextPartial.is_connected === false ? __spreadProps(__spreadValues({}, (_b = import_client.UserState.normalize(__spreadValues(__spreadValues({}, prev), nextPartial))) != null ? _b : prev), {
934
962
  address: void 0,
935
963
  chain_id: void 0,
936
964
  ens_name: void 0
937
- }) : (_c = import_client.UserState.normalize(__spreadValues(__spreadValues({}, prev), normalizedData))) != null ? _c : prev;
938
- StateChangeCallbacks.current.forEach((callback) => {
939
- callback(next);
940
- });
965
+ }) : (_c = import_client.UserState.normalize(__spreadValues(__spreadValues({}, prev), nextPartial))) != null ? _c : prev;
966
+ notifyStateChange(next);
941
967
  return next;
942
968
  });
943
- }, []);
969
+ }, [notifyStateChange, pruneUndefined]);
944
970
  const addExtValue = (0, import_react5.useCallback)((key, value) => {
945
971
  setUserState((prev) => {
946
972
  const next = import_client.UserState.withExt(prev, key, value);
947
- StateChangeCallbacks.current.forEach((callback) => {
948
- callback(next);
949
- });
973
+ notifyStateChange(next);
950
974
  return next;
951
975
  });
952
- }, []);
976
+ }, [notifyStateChange]);
953
977
  const removeExtValue = (0, import_react5.useCallback)((key) => {
954
978
  setUserState((prev) => {
955
979
  const ext = prev.ext;
@@ -961,12 +985,10 @@ function UserContextProvider({ children }) {
961
985
  const next = __spreadProps(__spreadValues({}, prev), {
962
986
  ext: Object.keys(nextExt).length > 0 ? nextExt : void 0
963
987
  });
964
- StateChangeCallbacks.current.forEach((callback) => {
965
- callback(next);
966
- });
988
+ notifyStateChange(next);
967
989
  return next;
968
990
  });
969
- }, []);
991
+ }, [notifyStateChange]);
970
992
  const getUserState = (0, import_react5.useCallback)(() => userRef.current, []);
971
993
  const onUserStateChange = (0, import_react5.useCallback)(
972
994
  (callback) => {
@@ -994,12 +1016,13 @@ function UserContextProvider({ children }) {
994
1016
  }
995
1017
 
996
1018
  // packages/react/src/runtime/core.tsx
997
- var import_react9 = require("react");
998
- var import_react10 = require("@assistant-ui/react");
999
- var import_client4 = require("@aomi-labs/client");
1019
+ var import_react10 = require("react");
1020
+ var import_react11 = require("@assistant-ui/react");
1021
+ var import_client5 = require("@aomi-labs/client");
1000
1022
 
1001
1023
  // packages/react/src/runtime/orchestrator.ts
1002
1024
  var import_react6 = require("react");
1025
+ var import_client4 = require("@aomi-labs/client");
1003
1026
 
1004
1027
  // packages/react/src/runtime/session-manager.ts
1005
1028
  var import_client3 = require("@aomi-labs/client");
@@ -1020,6 +1043,11 @@ var SessionManager = class {
1020
1043
  get(threadId) {
1021
1044
  return this.sessions.get(threadId);
1022
1045
  }
1046
+ forEach(callback) {
1047
+ for (const [threadId, session] of this.sessions) {
1048
+ callback(session, threadId);
1049
+ }
1050
+ }
1023
1051
  close(threadId) {
1024
1052
  const session = this.sessions.get(threadId);
1025
1053
  if (session) {
@@ -1155,14 +1183,30 @@ function useRuntimeOrchestrator(aomiClient, options) {
1155
1183
  (threadId) => {
1156
1184
  var _a, _b, _c, _d, _e;
1157
1185
  const manager = sessionManagerRef.current;
1186
+ const nextApp = options.getApp();
1187
+ const nextPublicKey = (_a = options.getPublicKey) == null ? void 0 : _a.call(options);
1188
+ const nextApiKey = (_c = (_b = options.getApiKey) == null ? void 0 : _b.call(options)) != null ? _c : void 0;
1189
+ const nextClientId = (_d = options.getClientId) == null ? void 0 : _d.call(options);
1190
+ const nextUserState = (_e = options.getUserState) == null ? void 0 : _e.call(options);
1158
1191
  const existing = manager.get(threadId);
1159
- if (existing) return existing;
1192
+ if (existing) {
1193
+ existing.syncRuntimeOptions({
1194
+ app: nextApp,
1195
+ publicKey: nextPublicKey,
1196
+ apiKey: nextApiKey,
1197
+ clientId: nextClientId,
1198
+ userState: nextUserState
1199
+ });
1200
+ return existing;
1201
+ }
1160
1202
  const session = manager.getOrCreate(threadId, {
1161
- app: options.getApp(),
1162
- publicKey: (_a = options.getPublicKey) == null ? void 0 : _a.call(options),
1163
- apiKey: (_c = (_b = options.getApiKey) == null ? void 0 : _b.call(options)) != null ? _c : void 0,
1164
- clientId: (_d = options.getClientId) == null ? void 0 : _d.call(options),
1165
- userState: (_e = options.getUserState) == null ? void 0 : _e.call(options)
1203
+ app: nextApp,
1204
+ publicKey: nextPublicKey,
1205
+ apiKey: nextApiKey,
1206
+ clientId: nextClientId,
1207
+ clientType: import_client4.CLIENT_TYPE_WEB_UI,
1208
+ syncPendingTxRequestsFromUserState: false,
1209
+ userState: nextUserState
1166
1210
  });
1167
1211
  const cleanups = [];
1168
1212
  cleanups.push(
@@ -1222,15 +1266,13 @@ function useRuntimeOrchestrator(aomiClient, options) {
1222
1266
  );
1223
1267
  const ensureInitialState = (0, import_react6.useCallback)(
1224
1268
  async (threadId) => {
1225
- var _a, _b;
1269
+ var _a;
1226
1270
  if (pendingFetches.current.has(threadId)) return;
1227
1271
  pendingFetches.current.add(threadId);
1228
1272
  try {
1229
1273
  const session = getSession(threadId);
1230
- const userState = (_a = options.getUserState) == null ? void 0 : _a.call(options);
1231
- if (userState) session.resolveUserState(userState);
1232
1274
  await session.fetchCurrentState();
1233
- (_b = options.onPendingRequestsChange) == null ? void 0 : _b.call(options, session.getPendingRequests());
1275
+ (_a = options.onPendingRequestsChange) == null ? void 0 : _a.call(options, session.getPendingRequests());
1234
1276
  if (threadContextRef.current.currentThreadId === threadId) {
1235
1277
  setIsRunning(session.getIsProcessing());
1236
1278
  }
@@ -1247,10 +1289,8 @@ function useRuntimeOrchestrator(aomiClient, options) {
1247
1289
  );
1248
1290
  const sendMessage = (0, import_react6.useCallback)(
1249
1291
  async (text, threadId) => {
1250
- var _a, _b;
1292
+ var _a;
1251
1293
  const session = getSession(threadId);
1252
- const userState = (_a = options.getUserState) == null ? void 0 : _a.call(options);
1253
- if (userState) session.resolveUserState(userState);
1254
1294
  const existingMessages = threadContextRef.current.getThreadMessages(threadId);
1255
1295
  const userMessage = {
1256
1296
  role: "user",
@@ -1265,7 +1305,7 @@ function useRuntimeOrchestrator(aomiClient, options) {
1265
1305
  lastActiveAt: (/* @__PURE__ */ new Date()).toISOString()
1266
1306
  });
1267
1307
  await session.sendAsync(text);
1268
- (_b = options.onPendingRequestsChange) == null ? void 0 : _b.call(options, session.getPendingRequests());
1308
+ (_a = options.onPendingRequestsChange) == null ? void 0 : _a.call(options, session.getPendingRequests());
1269
1309
  },
1270
1310
  [getSession]
1271
1311
  );
@@ -1537,8 +1577,41 @@ function useWalletHandler({
1537
1577
  };
1538
1578
  }
1539
1579
 
1540
- // packages/react/src/runtime/core.tsx
1580
+ // packages/react/src/runtime/user-state-provider.tsx
1581
+ var import_react9 = require("react");
1541
1582
  var import_jsx_runtime6 = require("react/jsx-runtime");
1583
+ function stableStateString(state) {
1584
+ return JSON.stringify(state != null ? state : {});
1585
+ }
1586
+ function RuntimeUserStateProvider({
1587
+ children,
1588
+ sessionManager,
1589
+ getUserState,
1590
+ onUserStateChange
1591
+ }) {
1592
+ const lastSerializedStateRef = (0, import_react9.useRef)("");
1593
+ (0, import_react9.useEffect)(() => {
1594
+ const applyToSessions = (next) => {
1595
+ const serialized = stableStateString(next);
1596
+ if (serialized === lastSerializedStateRef.current) {
1597
+ return;
1598
+ }
1599
+ lastSerializedStateRef.current = serialized;
1600
+ sessionManager.forEach((session) => {
1601
+ session.resolveUserState(next);
1602
+ });
1603
+ };
1604
+ applyToSessions(getUserState());
1605
+ const unsubscribe = onUserStateChange((next) => {
1606
+ applyToSessions(next);
1607
+ });
1608
+ return unsubscribe;
1609
+ }, [getUserState, onUserStateChange, sessionManager]);
1610
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_jsx_runtime6.Fragment, { children });
1611
+ }
1612
+
1613
+ // packages/react/src/runtime/core.tsx
1614
+ var import_jsx_runtime7 = require("react/jsx-runtime");
1542
1615
  function AomiRuntimeCore({
1543
1616
  children,
1544
1617
  aomiClient
@@ -1548,7 +1621,7 @@ function AomiRuntimeCore({
1548
1621
  const notificationContext = useNotification();
1549
1622
  const { user, onUserStateChange, getUserState } = useUser();
1550
1623
  const { getControlState, getCurrentThreadApp } = useControl();
1551
- const sessionManagerRef = (0, import_react9.useRef)(null);
1624
+ const sessionManagerRef = (0, import_react10.useRef)(null);
1552
1625
  const walletHandler = useWalletHandler({
1553
1626
  getSession: () => {
1554
1627
  var _a;
@@ -1565,7 +1638,7 @@ function AomiRuntimeCore({
1565
1638
  cancelGeneration: orchestratorCancel,
1566
1639
  aomiClientRef
1567
1640
  } = useRuntimeOrchestrator(aomiClient, {
1568
- getPublicKey: () => import_client4.UserState.isConnected(getUserState()) ? import_client4.UserState.address(getUserState()) : void 0,
1641
+ getPublicKey: () => import_client5.UserState.isConnected(getUserState()) ? import_client5.UserState.address(getUserState()) : void 0,
1569
1642
  getUserState,
1570
1643
  getApp: getCurrentThreadApp,
1571
1644
  getApiKey: () => getControlState().apiKey,
@@ -1577,20 +1650,20 @@ function AomiRuntimeCore({
1577
1650
  onEvent: (event) => eventContext.dispatch(event)
1578
1651
  });
1579
1652
  sessionManagerRef.current = sessionManager;
1580
- const walletSnapshot = (0, import_react9.useCallback)(
1653
+ const walletSnapshot = (0, import_react10.useCallback)(
1581
1654
  (nextUser) => {
1582
1655
  var _a;
1583
1656
  return {
1584
- address: import_client4.UserState.address(nextUser),
1585
- chain_id: import_client4.UserState.chainId(nextUser),
1586
- is_connected: (_a = import_client4.UserState.isConnected(nextUser)) != null ? _a : false,
1657
+ address: import_client5.UserState.address(nextUser),
1658
+ chain_id: import_client5.UserState.chainId(nextUser),
1659
+ is_connected: (_a = import_client5.UserState.isConnected(nextUser)) != null ? _a : false,
1587
1660
  ens_name: typeof nextUser.ens_name === "string" ? nextUser.ens_name : void 0
1588
1661
  };
1589
1662
  },
1590
1663
  [getUserState]
1591
1664
  );
1592
- const lastWalletStateRef = (0, import_react9.useRef)(walletSnapshot(getUserState()));
1593
- (0, import_react9.useEffect)(() => {
1665
+ const lastWalletStateRef = (0, import_react10.useRef)(walletSnapshot(getUserState()));
1666
+ (0, import_react10.useEffect)(() => {
1594
1667
  lastWalletStateRef.current = walletSnapshot(getUserState());
1595
1668
  const unsubscribe = onUserStateChange(async (newUser) => {
1596
1669
  const nextWalletState = walletSnapshot(newUser);
@@ -1614,11 +1687,11 @@ function AomiRuntimeCore({
1614
1687
  getUserState,
1615
1688
  walletSnapshot
1616
1689
  ]);
1617
- const threadContextRef = (0, import_react9.useRef)(threadContext);
1690
+ const threadContextRef = (0, import_react10.useRef)(threadContext);
1618
1691
  threadContextRef.current = threadContext;
1619
- const remoteThreadIdsRef = (0, import_react9.useRef)(/* @__PURE__ */ new Set());
1620
- const warmedThreadIdsRef = (0, import_react9.useRef)(/* @__PURE__ */ new Set());
1621
- const warmThread = (0, import_react9.useCallback)(
1692
+ const remoteThreadIdsRef = (0, import_react10.useRef)(/* @__PURE__ */ new Set());
1693
+ const warmedThreadIdsRef = (0, import_react10.useRef)(/* @__PURE__ */ new Set());
1694
+ const warmThread = (0, import_react10.useCallback)(
1622
1695
  async (threadId) => {
1623
1696
  if (!remoteThreadIdsRef.current.has(threadId) || warmedThreadIdsRef.current.has(threadId)) {
1624
1697
  return;
@@ -1626,13 +1699,13 @@ function AomiRuntimeCore({
1626
1699
  const userState = getUserState();
1627
1700
  await aomiClientRef.current.createThread(
1628
1701
  threadId,
1629
- import_client4.UserState.isConnected(userState) ? import_client4.UserState.address(userState) : void 0
1702
+ import_client5.UserState.isConnected(userState) ? import_client5.UserState.address(userState) : void 0
1630
1703
  );
1631
1704
  warmedThreadIdsRef.current.add(threadId);
1632
1705
  },
1633
1706
  [aomiClientRef, getUserState]
1634
1707
  );
1635
- (0, import_react9.useEffect)(() => {
1708
+ (0, import_react10.useEffect)(() => {
1636
1709
  const unsubscribe = eventContext.subscribe(
1637
1710
  "user_state_request",
1638
1711
  () => {
@@ -1647,7 +1720,7 @@ function AomiRuntimeCore({
1647
1720
  );
1648
1721
  return unsubscribe;
1649
1722
  }, [eventContext, threadContext.currentThreadId, getSession, getUserState]);
1650
- (0, import_react9.useEffect)(() => {
1723
+ (0, import_react10.useEffect)(() => {
1651
1724
  const threadId = threadContext.currentThreadId;
1652
1725
  let cancelled = false;
1653
1726
  void (async () => {
@@ -1660,7 +1733,7 @@ function AomiRuntimeCore({
1660
1733
  cancelled = true;
1661
1734
  };
1662
1735
  }, [ensureInitialState, threadContext.currentThreadId, warmThread]);
1663
- (0, import_react9.useEffect)(() => {
1736
+ (0, import_react10.useEffect)(() => {
1664
1737
  const threadId = threadContext.currentThreadId;
1665
1738
  const currentMeta = threadContext.getThreadMetadata(threadId);
1666
1739
  if (currentMeta && currentMeta.control.isProcessing !== isRunning) {
@@ -1674,8 +1747,8 @@ function AomiRuntimeCore({
1674
1747
  const currentMessages = threadContext.getThreadMessages(
1675
1748
  threadContext.currentThreadId
1676
1749
  );
1677
- (0, import_react9.useEffect)(() => {
1678
- const userAddress = import_client4.UserState.isConnected(user) ? import_client4.UserState.address(user) : void 0;
1750
+ (0, import_react10.useEffect)(() => {
1751
+ const userAddress = import_client5.UserState.isConnected(user) ? import_client5.UserState.address(user) : void 0;
1679
1752
  if (!userAddress) {
1680
1753
  remoteThreadIdsRef.current.clear();
1681
1754
  warmedThreadIdsRef.current.clear();
@@ -1729,7 +1802,7 @@ function AomiRuntimeCore({
1729
1802
  };
1730
1803
  void fetchThreadList();
1731
1804
  }, [user, aomiClientRef, ensureInitialState, warmThread]);
1732
- const threadListAdapter = (0, import_react9.useMemo)(
1805
+ const threadListAdapter = (0, import_react10.useMemo)(
1733
1806
  () => buildThreadListAdapter({
1734
1807
  aomiClientRef,
1735
1808
  threadContext,
@@ -1743,7 +1816,7 @@ function AomiRuntimeCore({
1743
1816
  threadContext.allThreadsMetadata
1744
1817
  ]
1745
1818
  );
1746
- (0, import_react9.useEffect)(() => {
1819
+ (0, import_react10.useEffect)(() => {
1747
1820
  const showToolNotification = (eventType) => (event) => {
1748
1821
  const payload = event.payload;
1749
1822
  const toolName = typeof (payload == null ? void 0 : payload.tool_name) === "string" ? payload.tool_name : void 0;
@@ -1768,12 +1841,12 @@ function AomiRuntimeCore({
1768
1841
  unsubscribeComplete();
1769
1842
  };
1770
1843
  }, [eventContext, notificationContext]);
1771
- (0, import_react9.useEffect)(() => {
1844
+ (0, import_react10.useEffect)(() => {
1772
1845
  const unsubscribe = eventContext.subscribe("system_notice", (_event) => {
1773
1846
  });
1774
1847
  return unsubscribe;
1775
1848
  }, [eventContext, notificationContext]);
1776
- const runtime = (0, import_react10.useExternalStoreRuntime)({
1849
+ const runtime = (0, import_react11.useExternalStoreRuntime)({
1777
1850
  messages: currentMessages,
1778
1851
  setMessages: (msgs) => threadContext.setThreadMessages(threadContext.currentThreadId, [...msgs]),
1779
1852
  isRunning,
@@ -1791,52 +1864,52 @@ function AomiRuntimeCore({
1791
1864
  convertMessage: (msg) => msg,
1792
1865
  adapters: { threadList: threadListAdapter }
1793
1866
  });
1794
- (0, import_react9.useEffect)(() => {
1867
+ (0, import_react10.useEffect)(() => {
1795
1868
  return () => {
1796
1869
  sessionManager.closeAll();
1797
1870
  };
1798
1871
  }, [sessionManager]);
1799
1872
  const userContext = useUser();
1800
- const sendMessage = (0, import_react9.useCallback)(
1873
+ const sendMessage = (0, import_react10.useCallback)(
1801
1874
  async (text) => {
1802
1875
  await orchestratorSendMessage(text, threadContext.currentThreadId);
1803
1876
  },
1804
1877
  [orchestratorSendMessage, threadContext.currentThreadId]
1805
1878
  );
1806
- const cancelGeneration = (0, import_react9.useCallback)(() => {
1879
+ const cancelGeneration = (0, import_react10.useCallback)(() => {
1807
1880
  void orchestratorCancel(threadContext.currentThreadId);
1808
1881
  }, [orchestratorCancel, threadContext.currentThreadId]);
1809
- const getMessages = (0, import_react9.useCallback)(
1882
+ const getMessages = (0, import_react10.useCallback)(
1810
1883
  (threadId) => {
1811
1884
  const id = threadId != null ? threadId : threadContext.currentThreadId;
1812
1885
  return threadContext.getThreadMessages(id);
1813
1886
  },
1814
1887
  [threadContext]
1815
1888
  );
1816
- const createThread = (0, import_react9.useCallback)(async () => {
1889
+ const createThread = (0, import_react10.useCallback)(async () => {
1817
1890
  await threadListAdapter.onSwitchToNewThread();
1818
1891
  return threadContextRef.current.currentThreadId;
1819
1892
  }, [threadListAdapter]);
1820
- const deleteThread = (0, import_react9.useCallback)(
1893
+ const deleteThread = (0, import_react10.useCallback)(
1821
1894
  async (threadId) => {
1822
1895
  sessionManager.close(threadId);
1823
1896
  await threadListAdapter.onDelete(threadId);
1824
1897
  },
1825
1898
  [threadListAdapter, sessionManager]
1826
1899
  );
1827
- const renameThread = (0, import_react9.useCallback)(
1900
+ const renameThread = (0, import_react10.useCallback)(
1828
1901
  async (threadId, title) => {
1829
1902
  await threadListAdapter.onRename(threadId, title);
1830
1903
  },
1831
1904
  [threadListAdapter]
1832
1905
  );
1833
- const archiveThread = (0, import_react9.useCallback)(
1906
+ const archiveThread = (0, import_react10.useCallback)(
1834
1907
  async (threadId) => {
1835
1908
  await threadListAdapter.onArchive(threadId);
1836
1909
  },
1837
1910
  [threadListAdapter]
1838
1911
  );
1839
- const selectThread = (0, import_react9.useCallback)(
1912
+ const selectThread = (0, import_react10.useCallback)(
1840
1913
  (threadId) => {
1841
1914
  if (threadContext.allThreadsMetadata.has(threadId)) {
1842
1915
  threadListAdapter.onSwitchToThread(threadId);
@@ -1846,7 +1919,7 @@ function AomiRuntimeCore({
1846
1919
  },
1847
1920
  [threadContext.allThreadsMetadata, threadListAdapter]
1848
1921
  );
1849
- const aomiRuntimeApi = (0, import_react9.useMemo)(
1922
+ const aomiRuntimeApi = (0, import_react10.useMemo)(
1850
1923
  () => ({
1851
1924
  // User API
1852
1925
  user: userContext.user,
@@ -1905,17 +1978,25 @@ function AomiRuntimeCore({
1905
1978
  eventContext
1906
1979
  ]
1907
1980
  );
1908
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(AomiRuntimeApiProvider, { value: aomiRuntimeApi, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_react10.AssistantRuntimeProvider, { runtime, children }) });
1981
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(AomiRuntimeApiProvider, { value: aomiRuntimeApi, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1982
+ RuntimeUserStateProvider,
1983
+ {
1984
+ sessionManager,
1985
+ getUserState: userContext.getUserState,
1986
+ onUserStateChange: userContext.onUserStateChange,
1987
+ children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_react11.AssistantRuntimeProvider, { runtime, children })
1988
+ }
1989
+ ) });
1909
1990
  }
1910
1991
 
1911
1992
  // packages/react/src/runtime/aomi-runtime.tsx
1912
- var import_jsx_runtime7 = require("react/jsx-runtime");
1993
+ var import_jsx_runtime8 = require("react/jsx-runtime");
1913
1994
  function AomiRuntimeProvider({
1914
1995
  children,
1915
1996
  backendUrl = "http://localhost:8080"
1916
1997
  }) {
1917
- const aomiClient = (0, import_react11.useMemo)(() => new import_client5.AomiClient({ baseUrl: backendUrl }), [backendUrl]);
1918
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ThreadContextProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(NotificationContextProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(UserContextProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(AomiRuntimeInner, { aomiClient, children }) }) }) });
1998
+ const aomiClient = (0, import_react12.useMemo)(() => new import_client6.AomiClient({ baseUrl: backendUrl }), [backendUrl]);
1999
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(ThreadContextProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(NotificationContextProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(UserContextProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(AomiRuntimeInner, { aomiClient, children }) }) }) });
1919
2000
  }
1920
2001
  function AomiRuntimeInner({
1921
2002
  children,
@@ -1924,20 +2005,20 @@ function AomiRuntimeInner({
1924
2005
  var _a;
1925
2006
  const threadContext = useThreadContext();
1926
2007
  const { user } = useUser();
1927
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2008
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1928
2009
  ControlContextProvider,
1929
2010
  {
1930
2011
  aomiClient,
1931
2012
  sessionId: threadContext.currentThreadId,
1932
- publicKey: import_client5.UserState.isConnected(user) ? (_a = import_client5.UserState.address(user)) != null ? _a : void 0 : void 0,
2013
+ publicKey: import_client6.UserState.isConnected(user) ? (_a = import_client6.UserState.address(user)) != null ? _a : void 0 : void 0,
1933
2014
  getThreadMetadata: threadContext.getThreadMetadata,
1934
2015
  updateThreadMetadata: threadContext.updateThreadMetadata,
1935
- children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2016
+ children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1936
2017
  EventContextProvider,
1937
2018
  {
1938
2019
  aomiClient,
1939
2020
  sessionId: threadContext.currentThreadId,
1940
- children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(AomiRuntimeCore, { aomiClient, children })
2021
+ children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(AomiRuntimeCore, { aomiClient, children })
1941
2022
  }
1942
2023
  )
1943
2024
  }
@@ -1945,7 +2026,7 @@ function AomiRuntimeInner({
1945
2026
  }
1946
2027
 
1947
2028
  // packages/react/src/handlers/notification-handler.ts
1948
- var import_react12 = require("react");
2029
+ var import_react13 = require("react");
1949
2030
  var notificationIdCounter2 = 0;
1950
2031
  function generateNotificationId() {
1951
2032
  return `notif-${Date.now()}-${++notificationIdCounter2}`;
@@ -1954,8 +2035,8 @@ function useNotificationHandler({
1954
2035
  onNotification
1955
2036
  } = {}) {
1956
2037
  const { subscribe } = useEventContext();
1957
- const [notifications, setNotifications] = (0, import_react12.useState)([]);
1958
- (0, import_react12.useEffect)(() => {
2038
+ const [notifications, setNotifications] = (0, import_react13.useState)([]);
2039
+ (0, import_react13.useEffect)(() => {
1959
2040
  const unsubscribe = subscribe("notification", (event) => {
1960
2041
  var _a, _b;
1961
2042
  const payload = event.payload;
@@ -1974,7 +2055,7 @@ function useNotificationHandler({
1974
2055
  return unsubscribe;
1975
2056
  }, [subscribe, onNotification]);
1976
2057
  const unhandledCount = notifications.filter((n) => !n.handled).length;
1977
- const markHandled = (0, import_react12.useCallback)((id) => {
2058
+ const markHandled = (0, import_react13.useCallback)((id) => {
1978
2059
  setNotifications(
1979
2060
  (prev) => prev.map((n) => n.id === id ? __spreadProps(__spreadValues({}, n), { handled: true }) : n)
1980
2061
  );
@@ -1990,16 +2071,24 @@ function useNotificationHandler({
1990
2071
  AomiClient,
1991
2072
  AomiRuntimeProvider,
1992
2073
  ControlContextProvider,
2074
+ DISABLED_PROVIDER_STATE,
1993
2075
  EventContextProvider,
1994
2076
  NotificationContextProvider,
2077
+ RuntimeUserStateProvider,
1995
2078
  SUPPORTED_CHAINS,
1996
2079
  ThreadContextProvider,
1997
2080
  UserContextProvider,
2081
+ aaModeFromExecutionKind,
1998
2082
  cn,
2083
+ executeWalletCalls,
1999
2084
  formatAddress,
2000
2085
  getChainInfo,
2001
2086
  getNetworkName,
2087
+ hydrateTxPayloadFromUserState,
2002
2088
  initThreadControl,
2089
+ parseChainId,
2090
+ toAAWalletCall,
2091
+ toAAWalletCalls,
2003
2092
  toViemSignTypedDataArgs,
2004
2093
  useAomiRuntime,
2005
2094
  useControl,