@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.cjs +151 -76
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +23 -9
- package/dist/index.d.ts +23 -9
- package/dist/index.js +123 -47
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
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: () =>
|
|
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
|
-
|
|
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
|
|
84
|
-
var
|
|
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
|
|
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),
|
|
938
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
998
|
-
var
|
|
999
|
-
var
|
|
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) {
|
|
@@ -1176,6 +1204,8 @@ function useRuntimeOrchestrator(aomiClient, options) {
|
|
|
1176
1204
|
publicKey: nextPublicKey,
|
|
1177
1205
|
apiKey: nextApiKey,
|
|
1178
1206
|
clientId: nextClientId,
|
|
1207
|
+
clientType: import_client4.CLIENT_TYPE_WEB_UI,
|
|
1208
|
+
syncPendingTxRequestsFromUserState: false,
|
|
1179
1209
|
userState: nextUserState
|
|
1180
1210
|
});
|
|
1181
1211
|
const cleanups = [];
|
|
@@ -1236,15 +1266,13 @@ function useRuntimeOrchestrator(aomiClient, options) {
|
|
|
1236
1266
|
);
|
|
1237
1267
|
const ensureInitialState = (0, import_react6.useCallback)(
|
|
1238
1268
|
async (threadId) => {
|
|
1239
|
-
var _a
|
|
1269
|
+
var _a;
|
|
1240
1270
|
if (pendingFetches.current.has(threadId)) return;
|
|
1241
1271
|
pendingFetches.current.add(threadId);
|
|
1242
1272
|
try {
|
|
1243
1273
|
const session = getSession(threadId);
|
|
1244
|
-
const userState = (_a = options.getUserState) == null ? void 0 : _a.call(options);
|
|
1245
|
-
if (userState) session.resolveUserState(userState);
|
|
1246
1274
|
await session.fetchCurrentState();
|
|
1247
|
-
(
|
|
1275
|
+
(_a = options.onPendingRequestsChange) == null ? void 0 : _a.call(options, session.getPendingRequests());
|
|
1248
1276
|
if (threadContextRef.current.currentThreadId === threadId) {
|
|
1249
1277
|
setIsRunning(session.getIsProcessing());
|
|
1250
1278
|
}
|
|
@@ -1261,10 +1289,8 @@ function useRuntimeOrchestrator(aomiClient, options) {
|
|
|
1261
1289
|
);
|
|
1262
1290
|
const sendMessage = (0, import_react6.useCallback)(
|
|
1263
1291
|
async (text, threadId) => {
|
|
1264
|
-
var _a
|
|
1292
|
+
var _a;
|
|
1265
1293
|
const session = getSession(threadId);
|
|
1266
|
-
const userState = (_a = options.getUserState) == null ? void 0 : _a.call(options);
|
|
1267
|
-
if (userState) session.resolveUserState(userState);
|
|
1268
1294
|
const existingMessages = threadContextRef.current.getThreadMessages(threadId);
|
|
1269
1295
|
const userMessage = {
|
|
1270
1296
|
role: "user",
|
|
@@ -1279,7 +1305,7 @@ function useRuntimeOrchestrator(aomiClient, options) {
|
|
|
1279
1305
|
lastActiveAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1280
1306
|
});
|
|
1281
1307
|
await session.sendAsync(text);
|
|
1282
|
-
(
|
|
1308
|
+
(_a = options.onPendingRequestsChange) == null ? void 0 : _a.call(options, session.getPendingRequests());
|
|
1283
1309
|
},
|
|
1284
1310
|
[getSession]
|
|
1285
1311
|
);
|
|
@@ -1551,8 +1577,41 @@ function useWalletHandler({
|
|
|
1551
1577
|
};
|
|
1552
1578
|
}
|
|
1553
1579
|
|
|
1554
|
-
// packages/react/src/runtime/
|
|
1580
|
+
// packages/react/src/runtime/user-state-provider.tsx
|
|
1581
|
+
var import_react9 = require("react");
|
|
1555
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");
|
|
1556
1615
|
function AomiRuntimeCore({
|
|
1557
1616
|
children,
|
|
1558
1617
|
aomiClient
|
|
@@ -1562,7 +1621,7 @@ function AomiRuntimeCore({
|
|
|
1562
1621
|
const notificationContext = useNotification();
|
|
1563
1622
|
const { user, onUserStateChange, getUserState } = useUser();
|
|
1564
1623
|
const { getControlState, getCurrentThreadApp } = useControl();
|
|
1565
|
-
const sessionManagerRef = (0,
|
|
1624
|
+
const sessionManagerRef = (0, import_react10.useRef)(null);
|
|
1566
1625
|
const walletHandler = useWalletHandler({
|
|
1567
1626
|
getSession: () => {
|
|
1568
1627
|
var _a;
|
|
@@ -1579,7 +1638,7 @@ function AomiRuntimeCore({
|
|
|
1579
1638
|
cancelGeneration: orchestratorCancel,
|
|
1580
1639
|
aomiClientRef
|
|
1581
1640
|
} = useRuntimeOrchestrator(aomiClient, {
|
|
1582
|
-
getPublicKey: () =>
|
|
1641
|
+
getPublicKey: () => import_client5.UserState.isConnected(getUserState()) ? import_client5.UserState.address(getUserState()) : void 0,
|
|
1583
1642
|
getUserState,
|
|
1584
1643
|
getApp: getCurrentThreadApp,
|
|
1585
1644
|
getApiKey: () => getControlState().apiKey,
|
|
@@ -1591,20 +1650,20 @@ function AomiRuntimeCore({
|
|
|
1591
1650
|
onEvent: (event) => eventContext.dispatch(event)
|
|
1592
1651
|
});
|
|
1593
1652
|
sessionManagerRef.current = sessionManager;
|
|
1594
|
-
const walletSnapshot = (0,
|
|
1653
|
+
const walletSnapshot = (0, import_react10.useCallback)(
|
|
1595
1654
|
(nextUser) => {
|
|
1596
1655
|
var _a;
|
|
1597
1656
|
return {
|
|
1598
|
-
address:
|
|
1599
|
-
chain_id:
|
|
1600
|
-
is_connected: (_a =
|
|
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,
|
|
1601
1660
|
ens_name: typeof nextUser.ens_name === "string" ? nextUser.ens_name : void 0
|
|
1602
1661
|
};
|
|
1603
1662
|
},
|
|
1604
1663
|
[getUserState]
|
|
1605
1664
|
);
|
|
1606
|
-
const lastWalletStateRef = (0,
|
|
1607
|
-
(0,
|
|
1665
|
+
const lastWalletStateRef = (0, import_react10.useRef)(walletSnapshot(getUserState()));
|
|
1666
|
+
(0, import_react10.useEffect)(() => {
|
|
1608
1667
|
lastWalletStateRef.current = walletSnapshot(getUserState());
|
|
1609
1668
|
const unsubscribe = onUserStateChange(async (newUser) => {
|
|
1610
1669
|
const nextWalletState = walletSnapshot(newUser);
|
|
@@ -1628,11 +1687,11 @@ function AomiRuntimeCore({
|
|
|
1628
1687
|
getUserState,
|
|
1629
1688
|
walletSnapshot
|
|
1630
1689
|
]);
|
|
1631
|
-
const threadContextRef = (0,
|
|
1690
|
+
const threadContextRef = (0, import_react10.useRef)(threadContext);
|
|
1632
1691
|
threadContextRef.current = threadContext;
|
|
1633
|
-
const remoteThreadIdsRef = (0,
|
|
1634
|
-
const warmedThreadIdsRef = (0,
|
|
1635
|
-
const warmThread = (0,
|
|
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)(
|
|
1636
1695
|
async (threadId) => {
|
|
1637
1696
|
if (!remoteThreadIdsRef.current.has(threadId) || warmedThreadIdsRef.current.has(threadId)) {
|
|
1638
1697
|
return;
|
|
@@ -1640,13 +1699,13 @@ function AomiRuntimeCore({
|
|
|
1640
1699
|
const userState = getUserState();
|
|
1641
1700
|
await aomiClientRef.current.createThread(
|
|
1642
1701
|
threadId,
|
|
1643
|
-
|
|
1702
|
+
import_client5.UserState.isConnected(userState) ? import_client5.UserState.address(userState) : void 0
|
|
1644
1703
|
);
|
|
1645
1704
|
warmedThreadIdsRef.current.add(threadId);
|
|
1646
1705
|
},
|
|
1647
1706
|
[aomiClientRef, getUserState]
|
|
1648
1707
|
);
|
|
1649
|
-
(0,
|
|
1708
|
+
(0, import_react10.useEffect)(() => {
|
|
1650
1709
|
const unsubscribe = eventContext.subscribe(
|
|
1651
1710
|
"user_state_request",
|
|
1652
1711
|
() => {
|
|
@@ -1661,7 +1720,7 @@ function AomiRuntimeCore({
|
|
|
1661
1720
|
);
|
|
1662
1721
|
return unsubscribe;
|
|
1663
1722
|
}, [eventContext, threadContext.currentThreadId, getSession, getUserState]);
|
|
1664
|
-
(0,
|
|
1723
|
+
(0, import_react10.useEffect)(() => {
|
|
1665
1724
|
const threadId = threadContext.currentThreadId;
|
|
1666
1725
|
let cancelled = false;
|
|
1667
1726
|
void (async () => {
|
|
@@ -1674,7 +1733,7 @@ function AomiRuntimeCore({
|
|
|
1674
1733
|
cancelled = true;
|
|
1675
1734
|
};
|
|
1676
1735
|
}, [ensureInitialState, threadContext.currentThreadId, warmThread]);
|
|
1677
|
-
(0,
|
|
1736
|
+
(0, import_react10.useEffect)(() => {
|
|
1678
1737
|
const threadId = threadContext.currentThreadId;
|
|
1679
1738
|
const currentMeta = threadContext.getThreadMetadata(threadId);
|
|
1680
1739
|
if (currentMeta && currentMeta.control.isProcessing !== isRunning) {
|
|
@@ -1688,8 +1747,8 @@ function AomiRuntimeCore({
|
|
|
1688
1747
|
const currentMessages = threadContext.getThreadMessages(
|
|
1689
1748
|
threadContext.currentThreadId
|
|
1690
1749
|
);
|
|
1691
|
-
(0,
|
|
1692
|
-
const userAddress =
|
|
1750
|
+
(0, import_react10.useEffect)(() => {
|
|
1751
|
+
const userAddress = import_client5.UserState.isConnected(user) ? import_client5.UserState.address(user) : void 0;
|
|
1693
1752
|
if (!userAddress) {
|
|
1694
1753
|
remoteThreadIdsRef.current.clear();
|
|
1695
1754
|
warmedThreadIdsRef.current.clear();
|
|
@@ -1743,7 +1802,7 @@ function AomiRuntimeCore({
|
|
|
1743
1802
|
};
|
|
1744
1803
|
void fetchThreadList();
|
|
1745
1804
|
}, [user, aomiClientRef, ensureInitialState, warmThread]);
|
|
1746
|
-
const threadListAdapter = (0,
|
|
1805
|
+
const threadListAdapter = (0, import_react10.useMemo)(
|
|
1747
1806
|
() => buildThreadListAdapter({
|
|
1748
1807
|
aomiClientRef,
|
|
1749
1808
|
threadContext,
|
|
@@ -1757,7 +1816,7 @@ function AomiRuntimeCore({
|
|
|
1757
1816
|
threadContext.allThreadsMetadata
|
|
1758
1817
|
]
|
|
1759
1818
|
);
|
|
1760
|
-
(0,
|
|
1819
|
+
(0, import_react10.useEffect)(() => {
|
|
1761
1820
|
const showToolNotification = (eventType) => (event) => {
|
|
1762
1821
|
const payload = event.payload;
|
|
1763
1822
|
const toolName = typeof (payload == null ? void 0 : payload.tool_name) === "string" ? payload.tool_name : void 0;
|
|
@@ -1782,12 +1841,12 @@ function AomiRuntimeCore({
|
|
|
1782
1841
|
unsubscribeComplete();
|
|
1783
1842
|
};
|
|
1784
1843
|
}, [eventContext, notificationContext]);
|
|
1785
|
-
(0,
|
|
1844
|
+
(0, import_react10.useEffect)(() => {
|
|
1786
1845
|
const unsubscribe = eventContext.subscribe("system_notice", (_event) => {
|
|
1787
1846
|
});
|
|
1788
1847
|
return unsubscribe;
|
|
1789
1848
|
}, [eventContext, notificationContext]);
|
|
1790
|
-
const runtime = (0,
|
|
1849
|
+
const runtime = (0, import_react11.useExternalStoreRuntime)({
|
|
1791
1850
|
messages: currentMessages,
|
|
1792
1851
|
setMessages: (msgs) => threadContext.setThreadMessages(threadContext.currentThreadId, [...msgs]),
|
|
1793
1852
|
isRunning,
|
|
@@ -1805,52 +1864,52 @@ function AomiRuntimeCore({
|
|
|
1805
1864
|
convertMessage: (msg) => msg,
|
|
1806
1865
|
adapters: { threadList: threadListAdapter }
|
|
1807
1866
|
});
|
|
1808
|
-
(0,
|
|
1867
|
+
(0, import_react10.useEffect)(() => {
|
|
1809
1868
|
return () => {
|
|
1810
1869
|
sessionManager.closeAll();
|
|
1811
1870
|
};
|
|
1812
1871
|
}, [sessionManager]);
|
|
1813
1872
|
const userContext = useUser();
|
|
1814
|
-
const sendMessage = (0,
|
|
1873
|
+
const sendMessage = (0, import_react10.useCallback)(
|
|
1815
1874
|
async (text) => {
|
|
1816
1875
|
await orchestratorSendMessage(text, threadContext.currentThreadId);
|
|
1817
1876
|
},
|
|
1818
1877
|
[orchestratorSendMessage, threadContext.currentThreadId]
|
|
1819
1878
|
);
|
|
1820
|
-
const cancelGeneration = (0,
|
|
1879
|
+
const cancelGeneration = (0, import_react10.useCallback)(() => {
|
|
1821
1880
|
void orchestratorCancel(threadContext.currentThreadId);
|
|
1822
1881
|
}, [orchestratorCancel, threadContext.currentThreadId]);
|
|
1823
|
-
const getMessages = (0,
|
|
1882
|
+
const getMessages = (0, import_react10.useCallback)(
|
|
1824
1883
|
(threadId) => {
|
|
1825
1884
|
const id = threadId != null ? threadId : threadContext.currentThreadId;
|
|
1826
1885
|
return threadContext.getThreadMessages(id);
|
|
1827
1886
|
},
|
|
1828
1887
|
[threadContext]
|
|
1829
1888
|
);
|
|
1830
|
-
const createThread = (0,
|
|
1889
|
+
const createThread = (0, import_react10.useCallback)(async () => {
|
|
1831
1890
|
await threadListAdapter.onSwitchToNewThread();
|
|
1832
1891
|
return threadContextRef.current.currentThreadId;
|
|
1833
1892
|
}, [threadListAdapter]);
|
|
1834
|
-
const deleteThread = (0,
|
|
1893
|
+
const deleteThread = (0, import_react10.useCallback)(
|
|
1835
1894
|
async (threadId) => {
|
|
1836
1895
|
sessionManager.close(threadId);
|
|
1837
1896
|
await threadListAdapter.onDelete(threadId);
|
|
1838
1897
|
},
|
|
1839
1898
|
[threadListAdapter, sessionManager]
|
|
1840
1899
|
);
|
|
1841
|
-
const renameThread = (0,
|
|
1900
|
+
const renameThread = (0, import_react10.useCallback)(
|
|
1842
1901
|
async (threadId, title) => {
|
|
1843
1902
|
await threadListAdapter.onRename(threadId, title);
|
|
1844
1903
|
},
|
|
1845
1904
|
[threadListAdapter]
|
|
1846
1905
|
);
|
|
1847
|
-
const archiveThread = (0,
|
|
1906
|
+
const archiveThread = (0, import_react10.useCallback)(
|
|
1848
1907
|
async (threadId) => {
|
|
1849
1908
|
await threadListAdapter.onArchive(threadId);
|
|
1850
1909
|
},
|
|
1851
1910
|
[threadListAdapter]
|
|
1852
1911
|
);
|
|
1853
|
-
const selectThread = (0,
|
|
1912
|
+
const selectThread = (0, import_react10.useCallback)(
|
|
1854
1913
|
(threadId) => {
|
|
1855
1914
|
if (threadContext.allThreadsMetadata.has(threadId)) {
|
|
1856
1915
|
threadListAdapter.onSwitchToThread(threadId);
|
|
@@ -1860,7 +1919,7 @@ function AomiRuntimeCore({
|
|
|
1860
1919
|
},
|
|
1861
1920
|
[threadContext.allThreadsMetadata, threadListAdapter]
|
|
1862
1921
|
);
|
|
1863
|
-
const aomiRuntimeApi = (0,
|
|
1922
|
+
const aomiRuntimeApi = (0, import_react10.useMemo)(
|
|
1864
1923
|
() => ({
|
|
1865
1924
|
// User API
|
|
1866
1925
|
user: userContext.user,
|
|
@@ -1919,17 +1978,25 @@ function AomiRuntimeCore({
|
|
|
1919
1978
|
eventContext
|
|
1920
1979
|
]
|
|
1921
1980
|
);
|
|
1922
|
-
return /* @__PURE__ */ (0,
|
|
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
|
+
) });
|
|
1923
1990
|
}
|
|
1924
1991
|
|
|
1925
1992
|
// packages/react/src/runtime/aomi-runtime.tsx
|
|
1926
|
-
var
|
|
1993
|
+
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
1927
1994
|
function AomiRuntimeProvider({
|
|
1928
1995
|
children,
|
|
1929
1996
|
backendUrl = "http://localhost:8080"
|
|
1930
1997
|
}) {
|
|
1931
|
-
const aomiClient = (0,
|
|
1932
|
-
return /* @__PURE__ */ (0,
|
|
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 }) }) }) });
|
|
1933
2000
|
}
|
|
1934
2001
|
function AomiRuntimeInner({
|
|
1935
2002
|
children,
|
|
@@ -1938,20 +2005,20 @@ function AomiRuntimeInner({
|
|
|
1938
2005
|
var _a;
|
|
1939
2006
|
const threadContext = useThreadContext();
|
|
1940
2007
|
const { user } = useUser();
|
|
1941
|
-
return /* @__PURE__ */ (0,
|
|
2008
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
1942
2009
|
ControlContextProvider,
|
|
1943
2010
|
{
|
|
1944
2011
|
aomiClient,
|
|
1945
2012
|
sessionId: threadContext.currentThreadId,
|
|
1946
|
-
publicKey:
|
|
2013
|
+
publicKey: import_client6.UserState.isConnected(user) ? (_a = import_client6.UserState.address(user)) != null ? _a : void 0 : void 0,
|
|
1947
2014
|
getThreadMetadata: threadContext.getThreadMetadata,
|
|
1948
2015
|
updateThreadMetadata: threadContext.updateThreadMetadata,
|
|
1949
|
-
children: /* @__PURE__ */ (0,
|
|
2016
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
1950
2017
|
EventContextProvider,
|
|
1951
2018
|
{
|
|
1952
2019
|
aomiClient,
|
|
1953
2020
|
sessionId: threadContext.currentThreadId,
|
|
1954
|
-
children: /* @__PURE__ */ (0,
|
|
2021
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(AomiRuntimeCore, { aomiClient, children })
|
|
1955
2022
|
}
|
|
1956
2023
|
)
|
|
1957
2024
|
}
|
|
@@ -1959,7 +2026,7 @@ function AomiRuntimeInner({
|
|
|
1959
2026
|
}
|
|
1960
2027
|
|
|
1961
2028
|
// packages/react/src/handlers/notification-handler.ts
|
|
1962
|
-
var
|
|
2029
|
+
var import_react13 = require("react");
|
|
1963
2030
|
var notificationIdCounter2 = 0;
|
|
1964
2031
|
function generateNotificationId() {
|
|
1965
2032
|
return `notif-${Date.now()}-${++notificationIdCounter2}`;
|
|
@@ -1968,8 +2035,8 @@ function useNotificationHandler({
|
|
|
1968
2035
|
onNotification
|
|
1969
2036
|
} = {}) {
|
|
1970
2037
|
const { subscribe } = useEventContext();
|
|
1971
|
-
const [notifications, setNotifications] = (0,
|
|
1972
|
-
(0,
|
|
2038
|
+
const [notifications, setNotifications] = (0, import_react13.useState)([]);
|
|
2039
|
+
(0, import_react13.useEffect)(() => {
|
|
1973
2040
|
const unsubscribe = subscribe("notification", (event) => {
|
|
1974
2041
|
var _a, _b;
|
|
1975
2042
|
const payload = event.payload;
|
|
@@ -1988,7 +2055,7 @@ function useNotificationHandler({
|
|
|
1988
2055
|
return unsubscribe;
|
|
1989
2056
|
}, [subscribe, onNotification]);
|
|
1990
2057
|
const unhandledCount = notifications.filter((n) => !n.handled).length;
|
|
1991
|
-
const markHandled = (0,
|
|
2058
|
+
const markHandled = (0, import_react13.useCallback)((id) => {
|
|
1992
2059
|
setNotifications(
|
|
1993
2060
|
(prev) => prev.map((n) => n.id === id ? __spreadProps(__spreadValues({}, n), { handled: true }) : n)
|
|
1994
2061
|
);
|
|
@@ -2004,16 +2071,24 @@ function useNotificationHandler({
|
|
|
2004
2071
|
AomiClient,
|
|
2005
2072
|
AomiRuntimeProvider,
|
|
2006
2073
|
ControlContextProvider,
|
|
2074
|
+
DISABLED_PROVIDER_STATE,
|
|
2007
2075
|
EventContextProvider,
|
|
2008
2076
|
NotificationContextProvider,
|
|
2077
|
+
RuntimeUserStateProvider,
|
|
2009
2078
|
SUPPORTED_CHAINS,
|
|
2010
2079
|
ThreadContextProvider,
|
|
2011
2080
|
UserContextProvider,
|
|
2081
|
+
aaModeFromExecutionKind,
|
|
2012
2082
|
cn,
|
|
2083
|
+
executeWalletCalls,
|
|
2013
2084
|
formatAddress,
|
|
2014
2085
|
getChainInfo,
|
|
2015
2086
|
getNetworkName,
|
|
2087
|
+
hydrateTxPayloadFromUserState,
|
|
2016
2088
|
initThreadControl,
|
|
2089
|
+
parseChainId,
|
|
2090
|
+
toAAWalletCall,
|
|
2091
|
+
toAAWalletCalls,
|
|
2017
2092
|
toViemSignTypedDataArgs,
|
|
2018
2093
|
useAomiRuntime,
|
|
2019
2094
|
useControl,
|