@aomi-labs/react 0.3.12 → 0.3.14

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,32 @@ 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,
58
+ MAX_AUTO_FEE_WEI: () => import_client8.MAX_AUTO_FEE_WEI,
57
59
  NotificationContextProvider: () => NotificationContextProvider,
60
+ RuntimeUserStateProvider: () => RuntimeUserStateProvider,
58
61
  SUPPORTED_CHAINS: () => SUPPORTED_CHAINS,
59
62
  ThreadContextProvider: () => ThreadContextProvider,
60
63
  UserContextProvider: () => UserContextProvider,
64
+ aaModeFromExecutionKind: () => import_client8.aaModeFromExecutionKind,
65
+ appendFeeCallToPayload: () => import_client8.appendFeeCallToPayload,
66
+ buildFeeAAWalletCall: () => import_client8.buildFeeAAWalletCall,
61
67
  cn: () => cn,
68
+ executeWalletCalls: () => import_client8.executeWalletCalls,
62
69
  formatAddress: () => formatAddress,
63
70
  getChainInfo: () => getChainInfo,
64
71
  getNetworkName: () => getNetworkName,
72
+ hydrateTxPayloadFromUserState: () => import_client8.hydrateTxPayloadFromUserState,
65
73
  initThreadControl: () => initThreadControl,
66
- toViemSignTypedDataArgs: () => import_client7.toViemSignTypedDataArgs,
74
+ normalizeSimulatedFee: () => import_client8.normalizeSimulatedFee,
75
+ parseChainId: () => import_client8.parseChainId,
76
+ toAAWalletCall: () => import_client8.toAAWalletCall,
77
+ toAAWalletCalls: () => import_client8.toAAWalletCalls,
78
+ toViemSignTypedDataArgs: () => import_client8.toViemSignTypedDataArgs,
67
79
  useAomiRuntime: () => useAomiRuntime,
68
80
  useControl: () => useControl,
69
81
  useCurrentThreadMessages: () => useCurrentThreadMessages,
@@ -76,12 +88,12 @@ __export(index_exports, {
76
88
  useWalletHandler: () => useWalletHandler
77
89
  });
78
90
  module.exports = __toCommonJS(index_exports);
79
- var import_client6 = require("@aomi-labs/client");
80
91
  var import_client7 = require("@aomi-labs/client");
92
+ var import_client8 = require("@aomi-labs/client");
81
93
 
82
94
  // packages/react/src/runtime/aomi-runtime.tsx
83
- var import_react11 = require("react");
84
- var import_client5 = require("@aomi-labs/client");
95
+ var import_react12 = require("react");
96
+ var import_client6 = require("@aomi-labs/client");
85
97
 
86
98
  // packages/react/src/contexts/control-context.tsx
87
99
  var import_react = require("react");
@@ -926,30 +938,46 @@ function UserContextProvider({ children }) {
926
938
  const StateChangeCallbacks = (0, import_react5.useRef)(
927
939
  /* @__PURE__ */ new Set()
928
940
  );
941
+ const notifyStateChange = (0, import_react5.useCallback)((next) => {
942
+ queueMicrotask(() => {
943
+ StateChangeCallbacks.current.forEach((callback) => {
944
+ callback(next);
945
+ });
946
+ });
947
+ }, []);
948
+ const pruneUndefined = (0, import_react5.useCallback)((state) => {
949
+ return Object.fromEntries(
950
+ Object.entries(state).filter(([, value]) => value !== void 0)
951
+ );
952
+ }, []);
929
953
  const setUser = (0, import_react5.useCallback)((data) => {
930
954
  setUserState((prev) => {
931
955
  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), {
956
+ const normalizedData = pruneUndefined((_a = import_client.UserState.normalize(data)) != null ? _a : {});
957
+ const nextPartial = __spreadValues({}, normalizedData);
958
+ if (nextPartial.is_connected === true && nextPartial.chain_id === void 0) {
959
+ if (prev.chain_id !== void 0) {
960
+ nextPartial.chain_id = prev.chain_id;
961
+ } else {
962
+ delete nextPartial.is_connected;
963
+ }
964
+ }
965
+ const next = nextPartial.is_connected === false ? __spreadProps(__spreadValues({}, (_b = import_client.UserState.normalize(__spreadValues(__spreadValues({}, prev), nextPartial))) != null ? _b : prev), {
934
966
  address: void 0,
935
967
  chain_id: void 0,
936
968
  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
- });
969
+ }) : (_c = import_client.UserState.normalize(__spreadValues(__spreadValues({}, prev), nextPartial))) != null ? _c : prev;
970
+ notifyStateChange(next);
941
971
  return next;
942
972
  });
943
- }, []);
973
+ }, [notifyStateChange, pruneUndefined]);
944
974
  const addExtValue = (0, import_react5.useCallback)((key, value) => {
945
975
  setUserState((prev) => {
946
976
  const next = import_client.UserState.withExt(prev, key, value);
947
- StateChangeCallbacks.current.forEach((callback) => {
948
- callback(next);
949
- });
977
+ notifyStateChange(next);
950
978
  return next;
951
979
  });
952
- }, []);
980
+ }, [notifyStateChange]);
953
981
  const removeExtValue = (0, import_react5.useCallback)((key) => {
954
982
  setUserState((prev) => {
955
983
  const ext = prev.ext;
@@ -961,12 +989,10 @@ function UserContextProvider({ children }) {
961
989
  const next = __spreadProps(__spreadValues({}, prev), {
962
990
  ext: Object.keys(nextExt).length > 0 ? nextExt : void 0
963
991
  });
964
- StateChangeCallbacks.current.forEach((callback) => {
965
- callback(next);
966
- });
992
+ notifyStateChange(next);
967
993
  return next;
968
994
  });
969
- }, []);
995
+ }, [notifyStateChange]);
970
996
  const getUserState = (0, import_react5.useCallback)(() => userRef.current, []);
971
997
  const onUserStateChange = (0, import_react5.useCallback)(
972
998
  (callback) => {
@@ -994,12 +1020,13 @@ function UserContextProvider({ children }) {
994
1020
  }
995
1021
 
996
1022
  // 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");
1023
+ var import_react10 = require("react");
1024
+ var import_react11 = require("@assistant-ui/react");
1025
+ var import_client5 = require("@aomi-labs/client");
1000
1026
 
1001
1027
  // packages/react/src/runtime/orchestrator.ts
1002
1028
  var import_react6 = require("react");
1029
+ var import_client4 = require("@aomi-labs/client");
1003
1030
 
1004
1031
  // packages/react/src/runtime/session-manager.ts
1005
1032
  var import_client3 = require("@aomi-labs/client");
@@ -1020,6 +1047,11 @@ var SessionManager = class {
1020
1047
  get(threadId) {
1021
1048
  return this.sessions.get(threadId);
1022
1049
  }
1050
+ forEach(callback) {
1051
+ for (const [threadId, session] of this.sessions) {
1052
+ callback(session, threadId);
1053
+ }
1054
+ }
1023
1055
  close(threadId) {
1024
1056
  const session = this.sessions.get(threadId);
1025
1057
  if (session) {
@@ -1176,6 +1208,8 @@ function useRuntimeOrchestrator(aomiClient, options) {
1176
1208
  publicKey: nextPublicKey,
1177
1209
  apiKey: nextApiKey,
1178
1210
  clientId: nextClientId,
1211
+ clientType: import_client4.CLIENT_TYPE_WEB_UI,
1212
+ syncPendingTxRequestsFromUserState: false,
1179
1213
  userState: nextUserState
1180
1214
  });
1181
1215
  const cleanups = [];
@@ -1236,15 +1270,13 @@ function useRuntimeOrchestrator(aomiClient, options) {
1236
1270
  );
1237
1271
  const ensureInitialState = (0, import_react6.useCallback)(
1238
1272
  async (threadId) => {
1239
- var _a, _b;
1273
+ var _a;
1240
1274
  if (pendingFetches.current.has(threadId)) return;
1241
1275
  pendingFetches.current.add(threadId);
1242
1276
  try {
1243
1277
  const session = getSession(threadId);
1244
- const userState = (_a = options.getUserState) == null ? void 0 : _a.call(options);
1245
- if (userState) session.resolveUserState(userState);
1246
1278
  await session.fetchCurrentState();
1247
- (_b = options.onPendingRequestsChange) == null ? void 0 : _b.call(options, session.getPendingRequests());
1279
+ (_a = options.onPendingRequestsChange) == null ? void 0 : _a.call(options, session.getPendingRequests());
1248
1280
  if (threadContextRef.current.currentThreadId === threadId) {
1249
1281
  setIsRunning(session.getIsProcessing());
1250
1282
  }
@@ -1261,10 +1293,8 @@ function useRuntimeOrchestrator(aomiClient, options) {
1261
1293
  );
1262
1294
  const sendMessage = (0, import_react6.useCallback)(
1263
1295
  async (text, threadId) => {
1264
- var _a, _b;
1296
+ var _a;
1265
1297
  const session = getSession(threadId);
1266
- const userState = (_a = options.getUserState) == null ? void 0 : _a.call(options);
1267
- if (userState) session.resolveUserState(userState);
1268
1298
  const existingMessages = threadContextRef.current.getThreadMessages(threadId);
1269
1299
  const userMessage = {
1270
1300
  role: "user",
@@ -1279,7 +1309,7 @@ function useRuntimeOrchestrator(aomiClient, options) {
1279
1309
  lastActiveAt: (/* @__PURE__ */ new Date()).toISOString()
1280
1310
  });
1281
1311
  await session.sendAsync(text);
1282
- (_b = options.onPendingRequestsChange) == null ? void 0 : _b.call(options, session.getPendingRequests());
1312
+ (_a = options.onPendingRequestsChange) == null ? void 0 : _a.call(options, session.getPendingRequests());
1283
1313
  },
1284
1314
  [getSession]
1285
1315
  );
@@ -1551,8 +1581,41 @@ function useWalletHandler({
1551
1581
  };
1552
1582
  }
1553
1583
 
1554
- // packages/react/src/runtime/core.tsx
1584
+ // packages/react/src/runtime/user-state-provider.tsx
1585
+ var import_react9 = require("react");
1555
1586
  var import_jsx_runtime6 = require("react/jsx-runtime");
1587
+ function stableStateString(state) {
1588
+ return JSON.stringify(state != null ? state : {});
1589
+ }
1590
+ function RuntimeUserStateProvider({
1591
+ children,
1592
+ sessionManager,
1593
+ getUserState,
1594
+ onUserStateChange
1595
+ }) {
1596
+ const lastSerializedStateRef = (0, import_react9.useRef)("");
1597
+ (0, import_react9.useEffect)(() => {
1598
+ const applyToSessions = (next) => {
1599
+ const serialized = stableStateString(next);
1600
+ if (serialized === lastSerializedStateRef.current) {
1601
+ return;
1602
+ }
1603
+ lastSerializedStateRef.current = serialized;
1604
+ sessionManager.forEach((session) => {
1605
+ session.resolveUserState(next);
1606
+ });
1607
+ };
1608
+ applyToSessions(getUserState());
1609
+ const unsubscribe = onUserStateChange((next) => {
1610
+ applyToSessions(next);
1611
+ });
1612
+ return unsubscribe;
1613
+ }, [getUserState, onUserStateChange, sessionManager]);
1614
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_jsx_runtime6.Fragment, { children });
1615
+ }
1616
+
1617
+ // packages/react/src/runtime/core.tsx
1618
+ var import_jsx_runtime7 = require("react/jsx-runtime");
1556
1619
  function AomiRuntimeCore({
1557
1620
  children,
1558
1621
  aomiClient
@@ -1562,7 +1625,7 @@ function AomiRuntimeCore({
1562
1625
  const notificationContext = useNotification();
1563
1626
  const { user, onUserStateChange, getUserState } = useUser();
1564
1627
  const { getControlState, getCurrentThreadApp } = useControl();
1565
- const sessionManagerRef = (0, import_react9.useRef)(null);
1628
+ const sessionManagerRef = (0, import_react10.useRef)(null);
1566
1629
  const walletHandler = useWalletHandler({
1567
1630
  getSession: () => {
1568
1631
  var _a;
@@ -1579,7 +1642,7 @@ function AomiRuntimeCore({
1579
1642
  cancelGeneration: orchestratorCancel,
1580
1643
  aomiClientRef
1581
1644
  } = useRuntimeOrchestrator(aomiClient, {
1582
- getPublicKey: () => import_client4.UserState.isConnected(getUserState()) ? import_client4.UserState.address(getUserState()) : void 0,
1645
+ getPublicKey: () => import_client5.UserState.isConnected(getUserState()) ? import_client5.UserState.address(getUserState()) : void 0,
1583
1646
  getUserState,
1584
1647
  getApp: getCurrentThreadApp,
1585
1648
  getApiKey: () => getControlState().apiKey,
@@ -1591,20 +1654,20 @@ function AomiRuntimeCore({
1591
1654
  onEvent: (event) => eventContext.dispatch(event)
1592
1655
  });
1593
1656
  sessionManagerRef.current = sessionManager;
1594
- const walletSnapshot = (0, import_react9.useCallback)(
1657
+ const walletSnapshot = (0, import_react10.useCallback)(
1595
1658
  (nextUser) => {
1596
1659
  var _a;
1597
1660
  return {
1598
- address: import_client4.UserState.address(nextUser),
1599
- chain_id: import_client4.UserState.chainId(nextUser),
1600
- is_connected: (_a = import_client4.UserState.isConnected(nextUser)) != null ? _a : false,
1661
+ address: import_client5.UserState.address(nextUser),
1662
+ chain_id: import_client5.UserState.chainId(nextUser),
1663
+ is_connected: (_a = import_client5.UserState.isConnected(nextUser)) != null ? _a : false,
1601
1664
  ens_name: typeof nextUser.ens_name === "string" ? nextUser.ens_name : void 0
1602
1665
  };
1603
1666
  },
1604
1667
  [getUserState]
1605
1668
  );
1606
- const lastWalletStateRef = (0, import_react9.useRef)(walletSnapshot(getUserState()));
1607
- (0, import_react9.useEffect)(() => {
1669
+ const lastWalletStateRef = (0, import_react10.useRef)(walletSnapshot(getUserState()));
1670
+ (0, import_react10.useEffect)(() => {
1608
1671
  lastWalletStateRef.current = walletSnapshot(getUserState());
1609
1672
  const unsubscribe = onUserStateChange(async (newUser) => {
1610
1673
  const nextWalletState = walletSnapshot(newUser);
@@ -1628,11 +1691,11 @@ function AomiRuntimeCore({
1628
1691
  getUserState,
1629
1692
  walletSnapshot
1630
1693
  ]);
1631
- const threadContextRef = (0, import_react9.useRef)(threadContext);
1694
+ const threadContextRef = (0, import_react10.useRef)(threadContext);
1632
1695
  threadContextRef.current = threadContext;
1633
- const remoteThreadIdsRef = (0, import_react9.useRef)(/* @__PURE__ */ new Set());
1634
- const warmedThreadIdsRef = (0, import_react9.useRef)(/* @__PURE__ */ new Set());
1635
- const warmThread = (0, import_react9.useCallback)(
1696
+ const remoteThreadIdsRef = (0, import_react10.useRef)(/* @__PURE__ */ new Set());
1697
+ const warmedThreadIdsRef = (0, import_react10.useRef)(/* @__PURE__ */ new Set());
1698
+ const warmThread = (0, import_react10.useCallback)(
1636
1699
  async (threadId) => {
1637
1700
  if (!remoteThreadIdsRef.current.has(threadId) || warmedThreadIdsRef.current.has(threadId)) {
1638
1701
  return;
@@ -1640,13 +1703,13 @@ function AomiRuntimeCore({
1640
1703
  const userState = getUserState();
1641
1704
  await aomiClientRef.current.createThread(
1642
1705
  threadId,
1643
- import_client4.UserState.isConnected(userState) ? import_client4.UserState.address(userState) : void 0
1706
+ import_client5.UserState.isConnected(userState) ? import_client5.UserState.address(userState) : void 0
1644
1707
  );
1645
1708
  warmedThreadIdsRef.current.add(threadId);
1646
1709
  },
1647
1710
  [aomiClientRef, getUserState]
1648
1711
  );
1649
- (0, import_react9.useEffect)(() => {
1712
+ (0, import_react10.useEffect)(() => {
1650
1713
  const unsubscribe = eventContext.subscribe(
1651
1714
  "user_state_request",
1652
1715
  () => {
@@ -1661,7 +1724,7 @@ function AomiRuntimeCore({
1661
1724
  );
1662
1725
  return unsubscribe;
1663
1726
  }, [eventContext, threadContext.currentThreadId, getSession, getUserState]);
1664
- (0, import_react9.useEffect)(() => {
1727
+ (0, import_react10.useEffect)(() => {
1665
1728
  const threadId = threadContext.currentThreadId;
1666
1729
  let cancelled = false;
1667
1730
  void (async () => {
@@ -1674,7 +1737,7 @@ function AomiRuntimeCore({
1674
1737
  cancelled = true;
1675
1738
  };
1676
1739
  }, [ensureInitialState, threadContext.currentThreadId, warmThread]);
1677
- (0, import_react9.useEffect)(() => {
1740
+ (0, import_react10.useEffect)(() => {
1678
1741
  const threadId = threadContext.currentThreadId;
1679
1742
  const currentMeta = threadContext.getThreadMetadata(threadId);
1680
1743
  if (currentMeta && currentMeta.control.isProcessing !== isRunning) {
@@ -1688,8 +1751,8 @@ function AomiRuntimeCore({
1688
1751
  const currentMessages = threadContext.getThreadMessages(
1689
1752
  threadContext.currentThreadId
1690
1753
  );
1691
- (0, import_react9.useEffect)(() => {
1692
- const userAddress = import_client4.UserState.isConnected(user) ? import_client4.UserState.address(user) : void 0;
1754
+ (0, import_react10.useEffect)(() => {
1755
+ const userAddress = import_client5.UserState.isConnected(user) ? import_client5.UserState.address(user) : void 0;
1693
1756
  if (!userAddress) {
1694
1757
  remoteThreadIdsRef.current.clear();
1695
1758
  warmedThreadIdsRef.current.clear();
@@ -1743,7 +1806,7 @@ function AomiRuntimeCore({
1743
1806
  };
1744
1807
  void fetchThreadList();
1745
1808
  }, [user, aomiClientRef, ensureInitialState, warmThread]);
1746
- const threadListAdapter = (0, import_react9.useMemo)(
1809
+ const threadListAdapter = (0, import_react10.useMemo)(
1747
1810
  () => buildThreadListAdapter({
1748
1811
  aomiClientRef,
1749
1812
  threadContext,
@@ -1757,7 +1820,7 @@ function AomiRuntimeCore({
1757
1820
  threadContext.allThreadsMetadata
1758
1821
  ]
1759
1822
  );
1760
- (0, import_react9.useEffect)(() => {
1823
+ (0, import_react10.useEffect)(() => {
1761
1824
  const showToolNotification = (eventType) => (event) => {
1762
1825
  const payload = event.payload;
1763
1826
  const toolName = typeof (payload == null ? void 0 : payload.tool_name) === "string" ? payload.tool_name : void 0;
@@ -1782,12 +1845,12 @@ function AomiRuntimeCore({
1782
1845
  unsubscribeComplete();
1783
1846
  };
1784
1847
  }, [eventContext, notificationContext]);
1785
- (0, import_react9.useEffect)(() => {
1848
+ (0, import_react10.useEffect)(() => {
1786
1849
  const unsubscribe = eventContext.subscribe("system_notice", (_event) => {
1787
1850
  });
1788
1851
  return unsubscribe;
1789
1852
  }, [eventContext, notificationContext]);
1790
- const runtime = (0, import_react10.useExternalStoreRuntime)({
1853
+ const runtime = (0, import_react11.useExternalStoreRuntime)({
1791
1854
  messages: currentMessages,
1792
1855
  setMessages: (msgs) => threadContext.setThreadMessages(threadContext.currentThreadId, [...msgs]),
1793
1856
  isRunning,
@@ -1805,52 +1868,52 @@ function AomiRuntimeCore({
1805
1868
  convertMessage: (msg) => msg,
1806
1869
  adapters: { threadList: threadListAdapter }
1807
1870
  });
1808
- (0, import_react9.useEffect)(() => {
1871
+ (0, import_react10.useEffect)(() => {
1809
1872
  return () => {
1810
1873
  sessionManager.closeAll();
1811
1874
  };
1812
1875
  }, [sessionManager]);
1813
1876
  const userContext = useUser();
1814
- const sendMessage = (0, import_react9.useCallback)(
1877
+ const sendMessage = (0, import_react10.useCallback)(
1815
1878
  async (text) => {
1816
1879
  await orchestratorSendMessage(text, threadContext.currentThreadId);
1817
1880
  },
1818
1881
  [orchestratorSendMessage, threadContext.currentThreadId]
1819
1882
  );
1820
- const cancelGeneration = (0, import_react9.useCallback)(() => {
1883
+ const cancelGeneration = (0, import_react10.useCallback)(() => {
1821
1884
  void orchestratorCancel(threadContext.currentThreadId);
1822
1885
  }, [orchestratorCancel, threadContext.currentThreadId]);
1823
- const getMessages = (0, import_react9.useCallback)(
1886
+ const getMessages = (0, import_react10.useCallback)(
1824
1887
  (threadId) => {
1825
1888
  const id = threadId != null ? threadId : threadContext.currentThreadId;
1826
1889
  return threadContext.getThreadMessages(id);
1827
1890
  },
1828
1891
  [threadContext]
1829
1892
  );
1830
- const createThread = (0, import_react9.useCallback)(async () => {
1893
+ const createThread = (0, import_react10.useCallback)(async () => {
1831
1894
  await threadListAdapter.onSwitchToNewThread();
1832
1895
  return threadContextRef.current.currentThreadId;
1833
1896
  }, [threadListAdapter]);
1834
- const deleteThread = (0, import_react9.useCallback)(
1897
+ const deleteThread = (0, import_react10.useCallback)(
1835
1898
  async (threadId) => {
1836
1899
  sessionManager.close(threadId);
1837
1900
  await threadListAdapter.onDelete(threadId);
1838
1901
  },
1839
1902
  [threadListAdapter, sessionManager]
1840
1903
  );
1841
- const renameThread = (0, import_react9.useCallback)(
1904
+ const renameThread = (0, import_react10.useCallback)(
1842
1905
  async (threadId, title) => {
1843
1906
  await threadListAdapter.onRename(threadId, title);
1844
1907
  },
1845
1908
  [threadListAdapter]
1846
1909
  );
1847
- const archiveThread = (0, import_react9.useCallback)(
1910
+ const archiveThread = (0, import_react10.useCallback)(
1848
1911
  async (threadId) => {
1849
1912
  await threadListAdapter.onArchive(threadId);
1850
1913
  },
1851
1914
  [threadListAdapter]
1852
1915
  );
1853
- const selectThread = (0, import_react9.useCallback)(
1916
+ const selectThread = (0, import_react10.useCallback)(
1854
1917
  (threadId) => {
1855
1918
  if (threadContext.allThreadsMetadata.has(threadId)) {
1856
1919
  threadListAdapter.onSwitchToThread(threadId);
@@ -1860,7 +1923,23 @@ function AomiRuntimeCore({
1860
1923
  },
1861
1924
  [threadContext.allThreadsMetadata, threadListAdapter]
1862
1925
  );
1863
- const aomiRuntimeApi = (0, import_react9.useMemo)(
1926
+ const simulateBatchTransactions = (0, import_react10.useCallback)(
1927
+ async (transactions, options) => {
1928
+ var _a, _b;
1929
+ const session = (_b = (_a = sessionManagerRef.current) == null ? void 0 : _a.get(threadContext.currentThreadId)) != null ? _b : getSession(threadContext.currentThreadId);
1930
+ if (!session) {
1931
+ throw new Error("runtime_session_unavailable");
1932
+ }
1933
+ const response = await session.client.simulateBatch(
1934
+ session.sessionId,
1935
+ transactions,
1936
+ options
1937
+ );
1938
+ return response.result;
1939
+ },
1940
+ [getSession, threadContext.currentThreadId]
1941
+ );
1942
+ const aomiRuntimeApi = (0, import_react10.useMemo)(
1864
1943
  () => ({
1865
1944
  // User API
1866
1945
  user: userContext.user,
@@ -1894,6 +1973,7 @@ function AomiRuntimeCore({
1894
1973
  startWalletRequest: walletHandler.startRequest,
1895
1974
  resolveWalletRequest: walletHandler.resolveRequest,
1896
1975
  rejectWalletRequest: walletHandler.rejectRequest,
1976
+ simulateBatchTransactions,
1897
1977
  // Event API
1898
1978
  subscribe: eventContext.subscribe,
1899
1979
  sendSystemCommand: eventContext.sendOutboundSystem,
@@ -1916,20 +1996,29 @@ function AomiRuntimeCore({
1916
1996
  cancelGeneration,
1917
1997
  notificationContext,
1918
1998
  walletHandler,
1999
+ simulateBatchTransactions,
1919
2000
  eventContext
1920
2001
  ]
1921
2002
  );
1922
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(AomiRuntimeApiProvider, { value: aomiRuntimeApi, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_react10.AssistantRuntimeProvider, { runtime, children }) });
2003
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(AomiRuntimeApiProvider, { value: aomiRuntimeApi, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2004
+ RuntimeUserStateProvider,
2005
+ {
2006
+ sessionManager,
2007
+ getUserState: userContext.getUserState,
2008
+ onUserStateChange: userContext.onUserStateChange,
2009
+ children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_react11.AssistantRuntimeProvider, { runtime, children })
2010
+ }
2011
+ ) });
1923
2012
  }
1924
2013
 
1925
2014
  // packages/react/src/runtime/aomi-runtime.tsx
1926
- var import_jsx_runtime7 = require("react/jsx-runtime");
2015
+ var import_jsx_runtime8 = require("react/jsx-runtime");
1927
2016
  function AomiRuntimeProvider({
1928
2017
  children,
1929
2018
  backendUrl = "http://localhost:8080"
1930
2019
  }) {
1931
- const aomiClient = (0, import_react11.useMemo)(() => new import_client5.AomiClient({ baseUrl: backendUrl }), [backendUrl]);
1932
- 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 }) }) }) });
2020
+ const aomiClient = (0, import_react12.useMemo)(() => new import_client6.AomiClient({ baseUrl: backendUrl }), [backendUrl]);
2021
+ 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 }) }) }) });
1933
2022
  }
1934
2023
  function AomiRuntimeInner({
1935
2024
  children,
@@ -1938,20 +2027,20 @@ function AomiRuntimeInner({
1938
2027
  var _a;
1939
2028
  const threadContext = useThreadContext();
1940
2029
  const { user } = useUser();
1941
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2030
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1942
2031
  ControlContextProvider,
1943
2032
  {
1944
2033
  aomiClient,
1945
2034
  sessionId: threadContext.currentThreadId,
1946
- publicKey: import_client5.UserState.isConnected(user) ? (_a = import_client5.UserState.address(user)) != null ? _a : void 0 : void 0,
2035
+ publicKey: import_client6.UserState.isConnected(user) ? (_a = import_client6.UserState.address(user)) != null ? _a : void 0 : void 0,
1947
2036
  getThreadMetadata: threadContext.getThreadMetadata,
1948
2037
  updateThreadMetadata: threadContext.updateThreadMetadata,
1949
- children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2038
+ children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1950
2039
  EventContextProvider,
1951
2040
  {
1952
2041
  aomiClient,
1953
2042
  sessionId: threadContext.currentThreadId,
1954
- children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(AomiRuntimeCore, { aomiClient, children })
2043
+ children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(AomiRuntimeCore, { aomiClient, children })
1955
2044
  }
1956
2045
  )
1957
2046
  }
@@ -1959,7 +2048,7 @@ function AomiRuntimeInner({
1959
2048
  }
1960
2049
 
1961
2050
  // packages/react/src/handlers/notification-handler.ts
1962
- var import_react12 = require("react");
2051
+ var import_react13 = require("react");
1963
2052
  var notificationIdCounter2 = 0;
1964
2053
  function generateNotificationId() {
1965
2054
  return `notif-${Date.now()}-${++notificationIdCounter2}`;
@@ -1968,8 +2057,8 @@ function useNotificationHandler({
1968
2057
  onNotification
1969
2058
  } = {}) {
1970
2059
  const { subscribe } = useEventContext();
1971
- const [notifications, setNotifications] = (0, import_react12.useState)([]);
1972
- (0, import_react12.useEffect)(() => {
2060
+ const [notifications, setNotifications] = (0, import_react13.useState)([]);
2061
+ (0, import_react13.useEffect)(() => {
1973
2062
  const unsubscribe = subscribe("notification", (event) => {
1974
2063
  var _a, _b;
1975
2064
  const payload = event.payload;
@@ -1988,7 +2077,7 @@ function useNotificationHandler({
1988
2077
  return unsubscribe;
1989
2078
  }, [subscribe, onNotification]);
1990
2079
  const unhandledCount = notifications.filter((n) => !n.handled).length;
1991
- const markHandled = (0, import_react12.useCallback)((id) => {
2080
+ const markHandled = (0, import_react13.useCallback)((id) => {
1992
2081
  setNotifications(
1993
2082
  (prev) => prev.map((n) => n.id === id ? __spreadProps(__spreadValues({}, n), { handled: true }) : n)
1994
2083
  );
@@ -2004,16 +2093,28 @@ function useNotificationHandler({
2004
2093
  AomiClient,
2005
2094
  AomiRuntimeProvider,
2006
2095
  ControlContextProvider,
2096
+ DISABLED_PROVIDER_STATE,
2007
2097
  EventContextProvider,
2098
+ MAX_AUTO_FEE_WEI,
2008
2099
  NotificationContextProvider,
2100
+ RuntimeUserStateProvider,
2009
2101
  SUPPORTED_CHAINS,
2010
2102
  ThreadContextProvider,
2011
2103
  UserContextProvider,
2104
+ aaModeFromExecutionKind,
2105
+ appendFeeCallToPayload,
2106
+ buildFeeAAWalletCall,
2012
2107
  cn,
2108
+ executeWalletCalls,
2013
2109
  formatAddress,
2014
2110
  getChainInfo,
2015
2111
  getNetworkName,
2112
+ hydrateTxPayloadFromUserState,
2016
2113
  initThreadControl,
2114
+ normalizeSimulatedFee,
2115
+ parseChainId,
2116
+ toAAWalletCall,
2117
+ toAAWalletCalls,
2017
2118
  toViemSignTypedDataArgs,
2018
2119
  useAomiRuntime,
2019
2120
  useControl,