@aomi-labs/react 0.3.12 → 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.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { AomiClient, Session, WalletRequest, UserState } from '@aomi-labs/client';
2
- export { AomiChatResponse, AomiClient, AomiClientOptions, AomiCreateThreadResponse, AomiInterruptResponse, AomiMessage, AomiSSEEvent, AomiStateResponse, AomiSystemEvent, AomiSystemResponse, AomiThread, UserState, WalletEip712Payload, WalletRequest, WalletTxPayload, toViemSignTypedDataArgs } from '@aomi-labs/client';
1
+ import { AomiClient, SessionOptions, Session, UserState, WalletRequest, WalletRequestResult } from '@aomi-labs/client';
2
+ export { AomiChatResponse, AomiClient, AomiClientOptions, AomiCreateThreadResponse, AomiInterruptResponse, AomiMessage, AomiSSEEvent, AomiStateResponse, AomiSystemEvent, AomiSystemResponse, AomiThread, DISABLED_PROVIDER_STATE, UserState, WalletEip712Payload, WalletRequest, WalletRequestResult, WalletTxPayload, aaModeFromExecutionKind, executeWalletCalls, hydrateTxPayloadFromUserState, parseChainId, toAAWalletCall, toAAWalletCalls, toViemSignTypedDataArgs } from '@aomi-labs/client';
3
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
4
  import { ReactNode, SetStateAction } from 'react';
5
5
  import { ThreadMessageLike } from '@assistant-ui/react';
@@ -11,6 +11,25 @@ type AomiRuntimeProviderProps = {
11
11
  };
12
12
  declare function AomiRuntimeProvider({ children, backendUrl, }: Readonly<AomiRuntimeProviderProps>): react_jsx_runtime.JSX.Element;
13
13
 
14
+ declare class SessionManager {
15
+ private readonly clientFactory;
16
+ private sessions;
17
+ constructor(clientFactory: () => AomiClient);
18
+ getOrCreate(threadId: string, opts: Omit<SessionOptions, "sessionId">): Session;
19
+ get(threadId: string): Session | undefined;
20
+ forEach(callback: (session: Session, threadId: string) => void): void;
21
+ close(threadId: string): void;
22
+ closeAll(): void;
23
+ }
24
+
25
+ type RuntimeUserStateProviderProps = {
26
+ children: ReactNode;
27
+ sessionManager: SessionManager;
28
+ getUserState: () => UserState;
29
+ onUserStateChange: (callback: (user: UserState) => void) => () => void;
30
+ };
31
+ declare function RuntimeUserStateProvider({ children, sessionManager, getUserState, onUserStateChange, }: RuntimeUserStateProviderProps): react_jsx_runtime.JSX.Element;
32
+
14
33
  type ThreadContext = {
15
34
  currentThreadId: string;
16
35
  setCurrentThreadId: (id: string) => void;
@@ -121,11 +140,6 @@ declare function NotificationContextProvider({ children, }: NotificationContextP
121
140
 
122
141
  type WalletRequestKind = "transaction" | "eip712_sign";
123
142
  type WalletRequestStatus = "pending" | "processing";
124
- type WalletRequestResult = {
125
- txHash?: string;
126
- signature?: string;
127
- amount?: string;
128
- };
129
143
  type WalletHandlerConfig = {
130
144
  /** Get the ClientSession for the current thread. */
131
145
  getSession: () => Session | undefined;
@@ -193,7 +207,7 @@ type AomiRuntimeApi = {
193
207
  clearAllNotifications: () => void;
194
208
  /** All queued wallet requests (tx + eip712 signing) */
195
209
  pendingWalletRequests: WalletRequest[];
196
- /** Mark a wallet request as being processed */
210
+ /** Mark a wallet request as in-flight suppresses it from the pending list until acked */
197
211
  startWalletRequest: (id: string) => void;
198
212
  /** Complete a wallet request after the backend acknowledges the response */
199
213
  resolveWalletRequest: (id: string, result: WalletRequestResult) => Promise<void>;
@@ -380,4 +394,4 @@ type ControlContextProviderProps = {
380
394
  };
381
395
  declare function ControlContextProvider({ children, aomiClient, sessionId, publicKey, getThreadMetadata, updateThreadMetadata, }: ControlContextProviderProps): react_jsx_runtime.JSX.Element;
382
396
 
383
- export { type AomiRuntimeApi, AomiRuntimeProvider, type AomiRuntimeProviderProps, type ChainInfo, type ControlContextApi, ControlContextProvider, type ControlContextProviderProps, type ControlState, type EventContext, EventContextProvider, type EventContextProviderProps, type EventSubscriber, type InboundEvent, type Notification$1 as Notification, type NotificationApi, NotificationContextProvider, type NotificationContextProviderProps, type NotificationContextApi as NotificationContextValue, type NotificationHandlerConfig, type NotificationType, type SSEStatus, SUPPORTED_CHAINS, type NotificationData as ShowNotificationParams, type StoredProviderKey, type ThreadContext, ThreadContextProvider, type ThreadControlState, type ThreadMetadata, type UserConfig, UserContextProvider, type WalletHandlerApi, type WalletHandlerConfig, type WalletRequestKind, type WalletRequestResult, type WalletRequestStatus, cn, formatAddress, getChainInfo, getNetworkName, initThreadControl, useAomiRuntime, useControl, useCurrentThreadMessages, useCurrentThreadMetadata, useEventContext, useNotification, useNotificationHandler, useThreadContext, useUser, useWalletHandler };
397
+ export { type AomiRuntimeApi, AomiRuntimeProvider, type AomiRuntimeProviderProps, type ChainInfo, type ControlContextApi, ControlContextProvider, type ControlContextProviderProps, type ControlState, type EventContext, EventContextProvider, type EventContextProviderProps, type EventSubscriber, type InboundEvent, type Notification$1 as Notification, type NotificationApi, NotificationContextProvider, type NotificationContextProviderProps, type NotificationContextApi as NotificationContextValue, type NotificationHandlerConfig, type NotificationType, RuntimeUserStateProvider, type SSEStatus, SUPPORTED_CHAINS, type NotificationData as ShowNotificationParams, type StoredProviderKey, type ThreadContext, ThreadContextProvider, type ThreadControlState, type ThreadMetadata, type UserConfig, UserContextProvider, type WalletHandlerApi, type WalletHandlerConfig, type WalletRequestKind, type WalletRequestStatus, cn, formatAddress, getChainInfo, getNetworkName, initThreadControl, useAomiRuntime, useControl, useCurrentThreadMessages, useCurrentThreadMetadata, useEventContext, useNotification, useNotificationHandler, useThreadContext, useUser, useWalletHandler };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { AomiClient, Session, WalletRequest, UserState } from '@aomi-labs/client';
2
- export { AomiChatResponse, AomiClient, AomiClientOptions, AomiCreateThreadResponse, AomiInterruptResponse, AomiMessage, AomiSSEEvent, AomiStateResponse, AomiSystemEvent, AomiSystemResponse, AomiThread, UserState, WalletEip712Payload, WalletRequest, WalletTxPayload, toViemSignTypedDataArgs } from '@aomi-labs/client';
1
+ import { AomiClient, SessionOptions, Session, UserState, WalletRequest, WalletRequestResult } from '@aomi-labs/client';
2
+ export { AomiChatResponse, AomiClient, AomiClientOptions, AomiCreateThreadResponse, AomiInterruptResponse, AomiMessage, AomiSSEEvent, AomiStateResponse, AomiSystemEvent, AomiSystemResponse, AomiThread, DISABLED_PROVIDER_STATE, UserState, WalletEip712Payload, WalletRequest, WalletRequestResult, WalletTxPayload, aaModeFromExecutionKind, executeWalletCalls, hydrateTxPayloadFromUserState, parseChainId, toAAWalletCall, toAAWalletCalls, toViemSignTypedDataArgs } from '@aomi-labs/client';
3
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
4
  import { ReactNode, SetStateAction } from 'react';
5
5
  import { ThreadMessageLike } from '@assistant-ui/react';
@@ -11,6 +11,25 @@ type AomiRuntimeProviderProps = {
11
11
  };
12
12
  declare function AomiRuntimeProvider({ children, backendUrl, }: Readonly<AomiRuntimeProviderProps>): react_jsx_runtime.JSX.Element;
13
13
 
14
+ declare class SessionManager {
15
+ private readonly clientFactory;
16
+ private sessions;
17
+ constructor(clientFactory: () => AomiClient);
18
+ getOrCreate(threadId: string, opts: Omit<SessionOptions, "sessionId">): Session;
19
+ get(threadId: string): Session | undefined;
20
+ forEach(callback: (session: Session, threadId: string) => void): void;
21
+ close(threadId: string): void;
22
+ closeAll(): void;
23
+ }
24
+
25
+ type RuntimeUserStateProviderProps = {
26
+ children: ReactNode;
27
+ sessionManager: SessionManager;
28
+ getUserState: () => UserState;
29
+ onUserStateChange: (callback: (user: UserState) => void) => () => void;
30
+ };
31
+ declare function RuntimeUserStateProvider({ children, sessionManager, getUserState, onUserStateChange, }: RuntimeUserStateProviderProps): react_jsx_runtime.JSX.Element;
32
+
14
33
  type ThreadContext = {
15
34
  currentThreadId: string;
16
35
  setCurrentThreadId: (id: string) => void;
@@ -121,11 +140,6 @@ declare function NotificationContextProvider({ children, }: NotificationContextP
121
140
 
122
141
  type WalletRequestKind = "transaction" | "eip712_sign";
123
142
  type WalletRequestStatus = "pending" | "processing";
124
- type WalletRequestResult = {
125
- txHash?: string;
126
- signature?: string;
127
- amount?: string;
128
- };
129
143
  type WalletHandlerConfig = {
130
144
  /** Get the ClientSession for the current thread. */
131
145
  getSession: () => Session | undefined;
@@ -193,7 +207,7 @@ type AomiRuntimeApi = {
193
207
  clearAllNotifications: () => void;
194
208
  /** All queued wallet requests (tx + eip712 signing) */
195
209
  pendingWalletRequests: WalletRequest[];
196
- /** Mark a wallet request as being processed */
210
+ /** Mark a wallet request as in-flight suppresses it from the pending list until acked */
197
211
  startWalletRequest: (id: string) => void;
198
212
  /** Complete a wallet request after the backend acknowledges the response */
199
213
  resolveWalletRequest: (id: string, result: WalletRequestResult) => Promise<void>;
@@ -380,4 +394,4 @@ type ControlContextProviderProps = {
380
394
  };
381
395
  declare function ControlContextProvider({ children, aomiClient, sessionId, publicKey, getThreadMetadata, updateThreadMetadata, }: ControlContextProviderProps): react_jsx_runtime.JSX.Element;
382
396
 
383
- export { type AomiRuntimeApi, AomiRuntimeProvider, type AomiRuntimeProviderProps, type ChainInfo, type ControlContextApi, ControlContextProvider, type ControlContextProviderProps, type ControlState, type EventContext, EventContextProvider, type EventContextProviderProps, type EventSubscriber, type InboundEvent, type Notification$1 as Notification, type NotificationApi, NotificationContextProvider, type NotificationContextProviderProps, type NotificationContextApi as NotificationContextValue, type NotificationHandlerConfig, type NotificationType, type SSEStatus, SUPPORTED_CHAINS, type NotificationData as ShowNotificationParams, type StoredProviderKey, type ThreadContext, ThreadContextProvider, type ThreadControlState, type ThreadMetadata, type UserConfig, UserContextProvider, type WalletHandlerApi, type WalletHandlerConfig, type WalletRequestKind, type WalletRequestResult, type WalletRequestStatus, cn, formatAddress, getChainInfo, getNetworkName, initThreadControl, useAomiRuntime, useControl, useCurrentThreadMessages, useCurrentThreadMetadata, useEventContext, useNotification, useNotificationHandler, useThreadContext, useUser, useWalletHandler };
397
+ export { type AomiRuntimeApi, AomiRuntimeProvider, type AomiRuntimeProviderProps, type ChainInfo, type ControlContextApi, ControlContextProvider, type ControlContextProviderProps, type ControlState, type EventContext, EventContextProvider, type EventContextProviderProps, type EventSubscriber, type InboundEvent, type Notification$1 as Notification, type NotificationApi, NotificationContextProvider, type NotificationContextProviderProps, type NotificationContextApi as NotificationContextValue, type NotificationHandlerConfig, type NotificationType, RuntimeUserStateProvider, type SSEStatus, SUPPORTED_CHAINS, type NotificationData as ShowNotificationParams, type StoredProviderKey, type ThreadContext, ThreadContextProvider, type ThreadControlState, type ThreadMetadata, type UserConfig, UserContextProvider, type WalletHandlerApi, type WalletHandlerConfig, type WalletRequestKind, type WalletRequestStatus, cn, formatAddress, getChainInfo, getNetworkName, initThreadControl, useAomiRuntime, useControl, useCurrentThreadMessages, useCurrentThreadMetadata, useEventContext, useNotification, useNotificationHandler, useThreadContext, useUser, useWalletHandler };
package/dist/index.js CHANGED
@@ -33,7 +33,16 @@ var __objRest = (source, exclude) => {
33
33
 
34
34
  // packages/react/src/index.ts
35
35
  import { AomiClient as AomiClient2 } from "@aomi-labs/client";
36
- import { toViemSignTypedDataArgs } from "@aomi-labs/client";
36
+ import {
37
+ toViemSignTypedDataArgs,
38
+ hydrateTxPayloadFromUserState,
39
+ toAAWalletCalls,
40
+ toAAWalletCall,
41
+ executeWalletCalls,
42
+ DISABLED_PROVIDER_STATE,
43
+ parseChainId,
44
+ aaModeFromExecutionKind
45
+ } from "@aomi-labs/client";
37
46
 
38
47
  // packages/react/src/runtime/aomi-runtime.tsx
39
48
  import { useMemo as useMemo3 } from "react";
@@ -911,30 +920,46 @@ function UserContextProvider({ children }) {
911
920
  const StateChangeCallbacks = useRef4(
912
921
  /* @__PURE__ */ new Set()
913
922
  );
923
+ const notifyStateChange = useCallback4((next) => {
924
+ queueMicrotask(() => {
925
+ StateChangeCallbacks.current.forEach((callback) => {
926
+ callback(next);
927
+ });
928
+ });
929
+ }, []);
930
+ const pruneUndefined = useCallback4((state) => {
931
+ return Object.fromEntries(
932
+ Object.entries(state).filter(([, value]) => value !== void 0)
933
+ );
934
+ }, []);
914
935
  const setUser = useCallback4((data) => {
915
936
  setUserState((prev) => {
916
937
  var _a, _b, _c;
917
- const normalizedData = (_a = UserState.normalize(data)) != null ? _a : {};
918
- const next = normalizedData.is_connected === false ? __spreadProps(__spreadValues({}, (_b = UserState.normalize(__spreadValues(__spreadValues({}, prev), normalizedData))) != null ? _b : prev), {
938
+ const normalizedData = pruneUndefined((_a = UserState.normalize(data)) != null ? _a : {});
939
+ const nextPartial = __spreadValues({}, normalizedData);
940
+ if (nextPartial.is_connected === true && nextPartial.chain_id === void 0) {
941
+ if (prev.chain_id !== void 0) {
942
+ nextPartial.chain_id = prev.chain_id;
943
+ } else {
944
+ delete nextPartial.is_connected;
945
+ }
946
+ }
947
+ const next = nextPartial.is_connected === false ? __spreadProps(__spreadValues({}, (_b = UserState.normalize(__spreadValues(__spreadValues({}, prev), nextPartial))) != null ? _b : prev), {
919
948
  address: void 0,
920
949
  chain_id: void 0,
921
950
  ens_name: void 0
922
- }) : (_c = UserState.normalize(__spreadValues(__spreadValues({}, prev), normalizedData))) != null ? _c : prev;
923
- StateChangeCallbacks.current.forEach((callback) => {
924
- callback(next);
925
- });
951
+ }) : (_c = UserState.normalize(__spreadValues(__spreadValues({}, prev), nextPartial))) != null ? _c : prev;
952
+ notifyStateChange(next);
926
953
  return next;
927
954
  });
928
- }, []);
955
+ }, [notifyStateChange, pruneUndefined]);
929
956
  const addExtValue = useCallback4((key, value) => {
930
957
  setUserState((prev) => {
931
958
  const next = UserState.withExt(prev, key, value);
932
- StateChangeCallbacks.current.forEach((callback) => {
933
- callback(next);
934
- });
959
+ notifyStateChange(next);
935
960
  return next;
936
961
  });
937
- }, []);
962
+ }, [notifyStateChange]);
938
963
  const removeExtValue = useCallback4((key) => {
939
964
  setUserState((prev) => {
940
965
  const ext = prev.ext;
@@ -946,12 +971,10 @@ function UserContextProvider({ children }) {
946
971
  const next = __spreadProps(__spreadValues({}, prev), {
947
972
  ext: Object.keys(nextExt).length > 0 ? nextExt : void 0
948
973
  });
949
- StateChangeCallbacks.current.forEach((callback) => {
950
- callback(next);
951
- });
974
+ notifyStateChange(next);
952
975
  return next;
953
976
  });
954
- }, []);
977
+ }, [notifyStateChange]);
955
978
  const getUserState = useCallback4(() => userRef.current, []);
956
979
  const onUserStateChange = useCallback4(
957
980
  (callback) => {
@@ -979,7 +1002,7 @@ function UserContextProvider({ children }) {
979
1002
  }
980
1003
 
981
1004
  // packages/react/src/runtime/core.tsx
982
- import { useCallback as useCallback7, useEffect as useEffect3, useMemo as useMemo2, useRef as useRef7 } from "react";
1005
+ import { useCallback as useCallback7, useEffect as useEffect4, useMemo as useMemo2, useRef as useRef8 } from "react";
983
1006
  import {
984
1007
  AssistantRuntimeProvider,
985
1008
  useExternalStoreRuntime
@@ -988,6 +1011,7 @@ import { UserState as UserState3 } from "@aomi-labs/client";
988
1011
 
989
1012
  // packages/react/src/runtime/orchestrator.ts
990
1013
  import { useCallback as useCallback5, useEffect as useEffect2, useRef as useRef5, useState as useState4 } from "react";
1014
+ import { CLIENT_TYPE_WEB_UI } from "@aomi-labs/client";
991
1015
 
992
1016
  // packages/react/src/runtime/session-manager.ts
993
1017
  import { Session as ClientSession } from "@aomi-labs/client";
@@ -1008,6 +1032,11 @@ var SessionManager = class {
1008
1032
  get(threadId) {
1009
1033
  return this.sessions.get(threadId);
1010
1034
  }
1035
+ forEach(callback) {
1036
+ for (const [threadId, session] of this.sessions) {
1037
+ callback(session, threadId);
1038
+ }
1039
+ }
1011
1040
  close(threadId) {
1012
1041
  const session = this.sessions.get(threadId);
1013
1042
  if (session) {
@@ -1164,6 +1193,8 @@ function useRuntimeOrchestrator(aomiClient, options) {
1164
1193
  publicKey: nextPublicKey,
1165
1194
  apiKey: nextApiKey,
1166
1195
  clientId: nextClientId,
1196
+ clientType: CLIENT_TYPE_WEB_UI,
1197
+ syncPendingTxRequestsFromUserState: false,
1167
1198
  userState: nextUserState
1168
1199
  });
1169
1200
  const cleanups = [];
@@ -1224,15 +1255,13 @@ function useRuntimeOrchestrator(aomiClient, options) {
1224
1255
  );
1225
1256
  const ensureInitialState = useCallback5(
1226
1257
  async (threadId) => {
1227
- var _a, _b;
1258
+ var _a;
1228
1259
  if (pendingFetches.current.has(threadId)) return;
1229
1260
  pendingFetches.current.add(threadId);
1230
1261
  try {
1231
1262
  const session = getSession(threadId);
1232
- const userState = (_a = options.getUserState) == null ? void 0 : _a.call(options);
1233
- if (userState) session.resolveUserState(userState);
1234
1263
  await session.fetchCurrentState();
1235
- (_b = options.onPendingRequestsChange) == null ? void 0 : _b.call(options, session.getPendingRequests());
1264
+ (_a = options.onPendingRequestsChange) == null ? void 0 : _a.call(options, session.getPendingRequests());
1236
1265
  if (threadContextRef.current.currentThreadId === threadId) {
1237
1266
  setIsRunning(session.getIsProcessing());
1238
1267
  }
@@ -1249,10 +1278,8 @@ function useRuntimeOrchestrator(aomiClient, options) {
1249
1278
  );
1250
1279
  const sendMessage = useCallback5(
1251
1280
  async (text, threadId) => {
1252
- var _a, _b;
1281
+ var _a;
1253
1282
  const session = getSession(threadId);
1254
- const userState = (_a = options.getUserState) == null ? void 0 : _a.call(options);
1255
- if (userState) session.resolveUserState(userState);
1256
1283
  const existingMessages = threadContextRef.current.getThreadMessages(threadId);
1257
1284
  const userMessage = {
1258
1285
  role: "user",
@@ -1267,7 +1294,7 @@ function useRuntimeOrchestrator(aomiClient, options) {
1267
1294
  lastActiveAt: (/* @__PURE__ */ new Date()).toISOString()
1268
1295
  });
1269
1296
  await session.sendAsync(text);
1270
- (_b = options.onPendingRequestsChange) == null ? void 0 : _b.call(options, session.getPendingRequests());
1297
+ (_a = options.onPendingRequestsChange) == null ? void 0 : _a.call(options, session.getPendingRequests());
1271
1298
  },
1272
1299
  [getSession]
1273
1300
  );
@@ -1539,8 +1566,41 @@ function useWalletHandler({
1539
1566
  };
1540
1567
  }
1541
1568
 
1569
+ // packages/react/src/runtime/user-state-provider.tsx
1570
+ import { useEffect as useEffect3, useRef as useRef7 } from "react";
1571
+ import { Fragment, jsx as jsx6 } from "react/jsx-runtime";
1572
+ function stableStateString(state) {
1573
+ return JSON.stringify(state != null ? state : {});
1574
+ }
1575
+ function RuntimeUserStateProvider({
1576
+ children,
1577
+ sessionManager,
1578
+ getUserState,
1579
+ onUserStateChange
1580
+ }) {
1581
+ const lastSerializedStateRef = useRef7("");
1582
+ useEffect3(() => {
1583
+ const applyToSessions = (next) => {
1584
+ const serialized = stableStateString(next);
1585
+ if (serialized === lastSerializedStateRef.current) {
1586
+ return;
1587
+ }
1588
+ lastSerializedStateRef.current = serialized;
1589
+ sessionManager.forEach((session) => {
1590
+ session.resolveUserState(next);
1591
+ });
1592
+ };
1593
+ applyToSessions(getUserState());
1594
+ const unsubscribe = onUserStateChange((next) => {
1595
+ applyToSessions(next);
1596
+ });
1597
+ return unsubscribe;
1598
+ }, [getUserState, onUserStateChange, sessionManager]);
1599
+ return /* @__PURE__ */ jsx6(Fragment, { children });
1600
+ }
1601
+
1542
1602
  // packages/react/src/runtime/core.tsx
1543
- import { jsx as jsx6 } from "react/jsx-runtime";
1603
+ import { jsx as jsx7 } from "react/jsx-runtime";
1544
1604
  function AomiRuntimeCore({
1545
1605
  children,
1546
1606
  aomiClient
@@ -1550,7 +1610,7 @@ function AomiRuntimeCore({
1550
1610
  const notificationContext = useNotification();
1551
1611
  const { user, onUserStateChange, getUserState } = useUser();
1552
1612
  const { getControlState, getCurrentThreadApp } = useControl();
1553
- const sessionManagerRef = useRef7(null);
1613
+ const sessionManagerRef = useRef8(null);
1554
1614
  const walletHandler = useWalletHandler({
1555
1615
  getSession: () => {
1556
1616
  var _a;
@@ -1591,8 +1651,8 @@ function AomiRuntimeCore({
1591
1651
  },
1592
1652
  [getUserState]
1593
1653
  );
1594
- const lastWalletStateRef = useRef7(walletSnapshot(getUserState()));
1595
- useEffect3(() => {
1654
+ const lastWalletStateRef = useRef8(walletSnapshot(getUserState()));
1655
+ useEffect4(() => {
1596
1656
  lastWalletStateRef.current = walletSnapshot(getUserState());
1597
1657
  const unsubscribe = onUserStateChange(async (newUser) => {
1598
1658
  const nextWalletState = walletSnapshot(newUser);
@@ -1616,10 +1676,10 @@ function AomiRuntimeCore({
1616
1676
  getUserState,
1617
1677
  walletSnapshot
1618
1678
  ]);
1619
- const threadContextRef = useRef7(threadContext);
1679
+ const threadContextRef = useRef8(threadContext);
1620
1680
  threadContextRef.current = threadContext;
1621
- const remoteThreadIdsRef = useRef7(/* @__PURE__ */ new Set());
1622
- const warmedThreadIdsRef = useRef7(/* @__PURE__ */ new Set());
1681
+ const remoteThreadIdsRef = useRef8(/* @__PURE__ */ new Set());
1682
+ const warmedThreadIdsRef = useRef8(/* @__PURE__ */ new Set());
1623
1683
  const warmThread = useCallback7(
1624
1684
  async (threadId) => {
1625
1685
  if (!remoteThreadIdsRef.current.has(threadId) || warmedThreadIdsRef.current.has(threadId)) {
@@ -1634,7 +1694,7 @@ function AomiRuntimeCore({
1634
1694
  },
1635
1695
  [aomiClientRef, getUserState]
1636
1696
  );
1637
- useEffect3(() => {
1697
+ useEffect4(() => {
1638
1698
  const unsubscribe = eventContext.subscribe(
1639
1699
  "user_state_request",
1640
1700
  () => {
@@ -1649,7 +1709,7 @@ function AomiRuntimeCore({
1649
1709
  );
1650
1710
  return unsubscribe;
1651
1711
  }, [eventContext, threadContext.currentThreadId, getSession, getUserState]);
1652
- useEffect3(() => {
1712
+ useEffect4(() => {
1653
1713
  const threadId = threadContext.currentThreadId;
1654
1714
  let cancelled = false;
1655
1715
  void (async () => {
@@ -1662,7 +1722,7 @@ function AomiRuntimeCore({
1662
1722
  cancelled = true;
1663
1723
  };
1664
1724
  }, [ensureInitialState, threadContext.currentThreadId, warmThread]);
1665
- useEffect3(() => {
1725
+ useEffect4(() => {
1666
1726
  const threadId = threadContext.currentThreadId;
1667
1727
  const currentMeta = threadContext.getThreadMetadata(threadId);
1668
1728
  if (currentMeta && currentMeta.control.isProcessing !== isRunning) {
@@ -1676,7 +1736,7 @@ function AomiRuntimeCore({
1676
1736
  const currentMessages = threadContext.getThreadMessages(
1677
1737
  threadContext.currentThreadId
1678
1738
  );
1679
- useEffect3(() => {
1739
+ useEffect4(() => {
1680
1740
  const userAddress = UserState3.isConnected(user) ? UserState3.address(user) : void 0;
1681
1741
  if (!userAddress) {
1682
1742
  remoteThreadIdsRef.current.clear();
@@ -1745,7 +1805,7 @@ function AomiRuntimeCore({
1745
1805
  threadContext.allThreadsMetadata
1746
1806
  ]
1747
1807
  );
1748
- useEffect3(() => {
1808
+ useEffect4(() => {
1749
1809
  const showToolNotification = (eventType) => (event) => {
1750
1810
  const payload = event.payload;
1751
1811
  const toolName = typeof (payload == null ? void 0 : payload.tool_name) === "string" ? payload.tool_name : void 0;
@@ -1770,7 +1830,7 @@ function AomiRuntimeCore({
1770
1830
  unsubscribeComplete();
1771
1831
  };
1772
1832
  }, [eventContext, notificationContext]);
1773
- useEffect3(() => {
1833
+ useEffect4(() => {
1774
1834
  const unsubscribe = eventContext.subscribe("system_notice", (_event) => {
1775
1835
  });
1776
1836
  return unsubscribe;
@@ -1793,7 +1853,7 @@ function AomiRuntimeCore({
1793
1853
  convertMessage: (msg) => msg,
1794
1854
  adapters: { threadList: threadListAdapter }
1795
1855
  });
1796
- useEffect3(() => {
1856
+ useEffect4(() => {
1797
1857
  return () => {
1798
1858
  sessionManager.closeAll();
1799
1859
  };
@@ -1907,17 +1967,25 @@ function AomiRuntimeCore({
1907
1967
  eventContext
1908
1968
  ]
1909
1969
  );
1910
- return /* @__PURE__ */ jsx6(AomiRuntimeApiProvider, { value: aomiRuntimeApi, children: /* @__PURE__ */ jsx6(AssistantRuntimeProvider, { runtime, children }) });
1970
+ return /* @__PURE__ */ jsx7(AomiRuntimeApiProvider, { value: aomiRuntimeApi, children: /* @__PURE__ */ jsx7(
1971
+ RuntimeUserStateProvider,
1972
+ {
1973
+ sessionManager,
1974
+ getUserState: userContext.getUserState,
1975
+ onUserStateChange: userContext.onUserStateChange,
1976
+ children: /* @__PURE__ */ jsx7(AssistantRuntimeProvider, { runtime, children })
1977
+ }
1978
+ ) });
1911
1979
  }
1912
1980
 
1913
1981
  // packages/react/src/runtime/aomi-runtime.tsx
1914
- import { jsx as jsx7 } from "react/jsx-runtime";
1982
+ import { jsx as jsx8 } from "react/jsx-runtime";
1915
1983
  function AomiRuntimeProvider({
1916
1984
  children,
1917
1985
  backendUrl = "http://localhost:8080"
1918
1986
  }) {
1919
1987
  const aomiClient = useMemo3(() => new AomiClient({ baseUrl: backendUrl }), [backendUrl]);
1920
- return /* @__PURE__ */ jsx7(ThreadContextProvider, { children: /* @__PURE__ */ jsx7(NotificationContextProvider, { children: /* @__PURE__ */ jsx7(UserContextProvider, { children: /* @__PURE__ */ jsx7(AomiRuntimeInner, { aomiClient, children }) }) }) });
1988
+ return /* @__PURE__ */ jsx8(ThreadContextProvider, { children: /* @__PURE__ */ jsx8(NotificationContextProvider, { children: /* @__PURE__ */ jsx8(UserContextProvider, { children: /* @__PURE__ */ jsx8(AomiRuntimeInner, { aomiClient, children }) }) }) });
1921
1989
  }
1922
1990
  function AomiRuntimeInner({
1923
1991
  children,
@@ -1926,7 +1994,7 @@ function AomiRuntimeInner({
1926
1994
  var _a;
1927
1995
  const threadContext = useThreadContext();
1928
1996
  const { user } = useUser();
1929
- return /* @__PURE__ */ jsx7(
1997
+ return /* @__PURE__ */ jsx8(
1930
1998
  ControlContextProvider,
1931
1999
  {
1932
2000
  aomiClient,
@@ -1934,12 +2002,12 @@ function AomiRuntimeInner({
1934
2002
  publicKey: UserState4.isConnected(user) ? (_a = UserState4.address(user)) != null ? _a : void 0 : void 0,
1935
2003
  getThreadMetadata: threadContext.getThreadMetadata,
1936
2004
  updateThreadMetadata: threadContext.updateThreadMetadata,
1937
- children: /* @__PURE__ */ jsx7(
2005
+ children: /* @__PURE__ */ jsx8(
1938
2006
  EventContextProvider,
1939
2007
  {
1940
2008
  aomiClient,
1941
2009
  sessionId: threadContext.currentThreadId,
1942
- children: /* @__PURE__ */ jsx7(AomiRuntimeCore, { aomiClient, children })
2010
+ children: /* @__PURE__ */ jsx8(AomiRuntimeCore, { aomiClient, children })
1943
2011
  }
1944
2012
  )
1945
2013
  }
@@ -1947,7 +2015,7 @@ function AomiRuntimeInner({
1947
2015
  }
1948
2016
 
1949
2017
  // packages/react/src/handlers/notification-handler.ts
1950
- import { useCallback as useCallback8, useEffect as useEffect4, useState as useState6 } from "react";
2018
+ import { useCallback as useCallback8, useEffect as useEffect5, useState as useState6 } from "react";
1951
2019
  var notificationIdCounter2 = 0;
1952
2020
  function generateNotificationId() {
1953
2021
  return `notif-${Date.now()}-${++notificationIdCounter2}`;
@@ -1957,7 +2025,7 @@ function useNotificationHandler({
1957
2025
  } = {}) {
1958
2026
  const { subscribe } = useEventContext();
1959
2027
  const [notifications, setNotifications] = useState6([]);
1960
- useEffect4(() => {
2028
+ useEffect5(() => {
1961
2029
  const unsubscribe = subscribe("notification", (event) => {
1962
2030
  var _a, _b;
1963
2031
  const payload = event.payload;
@@ -1991,16 +2059,24 @@ export {
1991
2059
  AomiClient2 as AomiClient,
1992
2060
  AomiRuntimeProvider,
1993
2061
  ControlContextProvider,
2062
+ DISABLED_PROVIDER_STATE,
1994
2063
  EventContextProvider,
1995
2064
  NotificationContextProvider,
2065
+ RuntimeUserStateProvider,
1996
2066
  SUPPORTED_CHAINS,
1997
2067
  ThreadContextProvider,
1998
2068
  UserContextProvider,
2069
+ aaModeFromExecutionKind,
1999
2070
  cn,
2071
+ executeWalletCalls,
2000
2072
  formatAddress,
2001
2073
  getChainInfo,
2002
2074
  getNetworkName,
2075
+ hydrateTxPayloadFromUserState,
2003
2076
  initThreadControl,
2077
+ parseChainId,
2078
+ toAAWalletCall,
2079
+ toAAWalletCalls,
2004
2080
  toViemSignTypedDataArgs,
2005
2081
  useAomiRuntime,
2006
2082
  useControl,