@aomi-labs/react 0.3.7 → 0.3.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/dist/index.cjs +21 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +21 -8
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -10,15 +10,15 @@ npm install @aomi-labs/react @assistant-ui/react react react-dom
|
|
|
10
10
|
pnpm add @aomi-labs/react @assistant-ui/react react react-dom
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
Optional dependencies
|
|
13
|
+
Optional dependencies when wiring wallet UI through Para + wagmi:
|
|
14
14
|
|
|
15
15
|
```bash
|
|
16
16
|
pnpm add wagmi viem
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
-
If you use the registry-installed `AomiFrame
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
If you use the registry-installed `AomiFrame` from `@aomi-labs/widget-lib`,
|
|
20
|
+
wallet behavior comes from the surrounding Para + wagmi provider tree.
|
|
21
|
+
`@aomi-labs/react` does not ship built-in wallet providers.
|
|
22
22
|
|
|
23
23
|
## Quick Start
|
|
24
24
|
|
package/dist/index.cjs
CHANGED
|
@@ -897,6 +897,16 @@ function useCurrentThreadMetadata() {
|
|
|
897
897
|
var import_react5 = require("react");
|
|
898
898
|
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
899
899
|
var UserContext = (0, import_react5.createContext)(void 0);
|
|
900
|
+
function normalizeUserState(next, data) {
|
|
901
|
+
if (data.isConnected === false) {
|
|
902
|
+
return __spreadProps(__spreadValues({}, next), {
|
|
903
|
+
address: void 0,
|
|
904
|
+
chainId: void 0,
|
|
905
|
+
ensName: void 0
|
|
906
|
+
});
|
|
907
|
+
}
|
|
908
|
+
return next;
|
|
909
|
+
}
|
|
900
910
|
function useUser() {
|
|
901
911
|
const context = (0, import_react5.useContext)(UserContext);
|
|
902
912
|
if (!context) {
|
|
@@ -926,7 +936,7 @@ function UserContextProvider({ children }) {
|
|
|
926
936
|
);
|
|
927
937
|
const setUser = (0, import_react5.useCallback)((data) => {
|
|
928
938
|
setUserState((prev) => {
|
|
929
|
-
const next = __spreadValues(__spreadValues({}, prev), data);
|
|
939
|
+
const next = normalizeUserState(__spreadValues(__spreadValues({}, prev), data), data);
|
|
930
940
|
StateChangeCallbacks.current.forEach((callback) => {
|
|
931
941
|
callback(next);
|
|
932
942
|
});
|
|
@@ -1502,7 +1512,7 @@ function AomiRuntimeCore({
|
|
|
1502
1512
|
const eventContext = useEventContext();
|
|
1503
1513
|
const notificationContext = useNotification();
|
|
1504
1514
|
const { user, onUserStateChange, getUserState } = useUser();
|
|
1505
|
-
const { getControlState, getCurrentThreadApp
|
|
1515
|
+
const { getControlState, getCurrentThreadApp } = useControl();
|
|
1506
1516
|
const sessionManagerRef = (0, import_react9.useRef)(null);
|
|
1507
1517
|
const walletHandler = useWalletHandler({
|
|
1508
1518
|
getSession: () => {
|
|
@@ -1520,7 +1530,11 @@ function AomiRuntimeCore({
|
|
|
1520
1530
|
cancelGeneration: orchestratorCancel,
|
|
1521
1531
|
aomiClientRef
|
|
1522
1532
|
} = useRuntimeOrchestrator(aomiClient, {
|
|
1523
|
-
getPublicKey: () =>
|
|
1533
|
+
getPublicKey: () => {
|
|
1534
|
+
var _a;
|
|
1535
|
+
const userState = getUserState();
|
|
1536
|
+
return userState.isConnected ? (_a = userState.address) != null ? _a : void 0 : void 0;
|
|
1537
|
+
},
|
|
1524
1538
|
getUserState,
|
|
1525
1539
|
getApp: getCurrentThreadApp,
|
|
1526
1540
|
getApiKey: () => getControlState().apiKey,
|
|
@@ -1603,7 +1617,7 @@ function AomiRuntimeCore({
|
|
|
1603
1617
|
threadContext.currentThreadId
|
|
1604
1618
|
);
|
|
1605
1619
|
(0, import_react9.useEffect)(() => {
|
|
1606
|
-
const userAddress = user.address;
|
|
1620
|
+
const userAddress = user.isConnected ? user.address : void 0;
|
|
1607
1621
|
if (!userAddress) return;
|
|
1608
1622
|
const fetchThreadList = async () => {
|
|
1609
1623
|
var _a, _b, _c;
|
|
@@ -1640,7 +1654,7 @@ function AomiRuntimeCore({
|
|
|
1640
1654
|
}
|
|
1641
1655
|
};
|
|
1642
1656
|
void fetchThreadList();
|
|
1643
|
-
}, [user.address, aomiClientRef]);
|
|
1657
|
+
}, [user.address, user.isConnected, aomiClientRef]);
|
|
1644
1658
|
const threadListAdapter = (0, import_react9.useMemo)(
|
|
1645
1659
|
() => buildThreadListAdapter({
|
|
1646
1660
|
aomiClientRef,
|
|
@@ -1706,9 +1720,8 @@ function AomiRuntimeCore({
|
|
|
1706
1720
|
(0, import_react9.useEffect)(() => {
|
|
1707
1721
|
return () => {
|
|
1708
1722
|
sessionManager.closeAll();
|
|
1709
|
-
void clearSecrets();
|
|
1710
1723
|
};
|
|
1711
|
-
}, [sessionManager
|
|
1724
|
+
}, [sessionManager]);
|
|
1712
1725
|
const userContext = useUser();
|
|
1713
1726
|
const sendMessage = (0, import_react9.useCallback)(
|
|
1714
1727
|
async (text) => {
|
|
@@ -1844,7 +1857,7 @@ function AomiRuntimeInner({
|
|
|
1844
1857
|
{
|
|
1845
1858
|
aomiClient,
|
|
1846
1859
|
sessionId: threadContext.currentThreadId,
|
|
1847
|
-
publicKey: (_a = user.address) != null ? _a : void 0,
|
|
1860
|
+
publicKey: user.isConnected ? (_a = user.address) != null ? _a : void 0 : void 0,
|
|
1848
1861
|
getThreadMetadata: threadContext.getThreadMetadata,
|
|
1849
1862
|
updateThreadMetadata: threadContext.updateThreadMetadata,
|
|
1850
1863
|
children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|