@aomi-labs/react 0.3.9 → 0.3.11
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 +159 -87
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +25 -30
- package/dist/index.d.ts +25 -30
- package/dist/index.js +152 -80
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -50,7 +50,7 @@ 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_client6.AomiClient,
|
|
54
54
|
AomiRuntimeProvider: () => AomiRuntimeProvider,
|
|
55
55
|
ControlContextProvider: () => ControlContextProvider,
|
|
56
56
|
EventContextProvider: () => EventContextProvider,
|
|
@@ -63,7 +63,7 @@ __export(index_exports, {
|
|
|
63
63
|
getChainInfo: () => getChainInfo,
|
|
64
64
|
getNetworkName: () => getNetworkName,
|
|
65
65
|
initThreadControl: () => initThreadControl,
|
|
66
|
-
toViemSignTypedDataArgs: () =>
|
|
66
|
+
toViemSignTypedDataArgs: () => import_client7.toViemSignTypedDataArgs,
|
|
67
67
|
useAomiRuntime: () => useAomiRuntime,
|
|
68
68
|
useControl: () => useControl,
|
|
69
69
|
useCurrentThreadMessages: () => useCurrentThreadMessages,
|
|
@@ -76,12 +76,12 @@ __export(index_exports, {
|
|
|
76
76
|
useWalletHandler: () => useWalletHandler
|
|
77
77
|
});
|
|
78
78
|
module.exports = __toCommonJS(index_exports);
|
|
79
|
-
var
|
|
80
|
-
var
|
|
79
|
+
var import_client6 = require("@aomi-labs/client");
|
|
80
|
+
var import_client7 = require("@aomi-labs/client");
|
|
81
81
|
|
|
82
82
|
// packages/react/src/runtime/aomi-runtime.tsx
|
|
83
83
|
var import_react11 = require("react");
|
|
84
|
-
var
|
|
84
|
+
var import_client5 = require("@aomi-labs/client");
|
|
85
85
|
|
|
86
86
|
// packages/react/src/contexts/control-context.tsx
|
|
87
87
|
var import_react = require("react");
|
|
@@ -895,18 +895,10 @@ function useCurrentThreadMetadata() {
|
|
|
895
895
|
|
|
896
896
|
// packages/react/src/contexts/user-context.tsx
|
|
897
897
|
var import_react5 = require("react");
|
|
898
|
+
var import_client = require("@aomi-labs/client");
|
|
899
|
+
var import_client2 = require("@aomi-labs/client");
|
|
898
900
|
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
899
901
|
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
|
-
}
|
|
910
902
|
function useUser() {
|
|
911
903
|
const context = (0, import_react5.useContext)(UserContext);
|
|
912
904
|
if (!context) {
|
|
@@ -923,10 +915,10 @@ function useUser() {
|
|
|
923
915
|
}
|
|
924
916
|
function UserContextProvider({ children }) {
|
|
925
917
|
const [user, setUserState] = (0, import_react5.useState)({
|
|
926
|
-
isConnected: false,
|
|
927
918
|
address: void 0,
|
|
928
|
-
|
|
929
|
-
|
|
919
|
+
chain_id: void 0,
|
|
920
|
+
is_connected: false,
|
|
921
|
+
ens_name: void 0,
|
|
930
922
|
ext: void 0
|
|
931
923
|
});
|
|
932
924
|
const userRef = (0, import_react5.useRef)(user);
|
|
@@ -936,7 +928,13 @@ function UserContextProvider({ children }) {
|
|
|
936
928
|
);
|
|
937
929
|
const setUser = (0, import_react5.useCallback)((data) => {
|
|
938
930
|
setUserState((prev) => {
|
|
939
|
-
|
|
931
|
+
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), {
|
|
934
|
+
address: void 0,
|
|
935
|
+
chain_id: void 0,
|
|
936
|
+
ens_name: void 0
|
|
937
|
+
}) : (_c = import_client.UserState.normalize(__spreadValues(__spreadValues({}, prev), normalizedData))) != null ? _c : prev;
|
|
940
938
|
StateChangeCallbacks.current.forEach((callback) => {
|
|
941
939
|
callback(next);
|
|
942
940
|
});
|
|
@@ -945,12 +943,7 @@ function UserContextProvider({ children }) {
|
|
|
945
943
|
}, []);
|
|
946
944
|
const addExtValue = (0, import_react5.useCallback)((key, value) => {
|
|
947
945
|
setUserState((prev) => {
|
|
948
|
-
|
|
949
|
-
const next = __spreadProps(__spreadValues({}, prev), {
|
|
950
|
-
ext: __spreadProps(__spreadValues({}, (_a = prev.ext) != null ? _a : {}), {
|
|
951
|
-
[key]: value
|
|
952
|
-
})
|
|
953
|
-
});
|
|
946
|
+
const next = import_client.UserState.withExt(prev, key, value);
|
|
954
947
|
StateChangeCallbacks.current.forEach((callback) => {
|
|
955
948
|
callback(next);
|
|
956
949
|
});
|
|
@@ -959,10 +952,11 @@ function UserContextProvider({ children }) {
|
|
|
959
952
|
}, []);
|
|
960
953
|
const removeExtValue = (0, import_react5.useCallback)((key) => {
|
|
961
954
|
setUserState((prev) => {
|
|
962
|
-
|
|
955
|
+
const ext = prev.ext;
|
|
956
|
+
if (typeof ext !== "object" || ext === null || Array.isArray(ext) || !(key in ext)) {
|
|
963
957
|
return prev;
|
|
964
958
|
}
|
|
965
|
-
const nextExt = __spreadValues({},
|
|
959
|
+
const nextExt = __spreadValues({}, ext);
|
|
966
960
|
delete nextExt[key];
|
|
967
961
|
const next = __spreadProps(__spreadValues({}, prev), {
|
|
968
962
|
ext: Object.keys(nextExt).length > 0 ? nextExt : void 0
|
|
@@ -1002,12 +996,13 @@ function UserContextProvider({ children }) {
|
|
|
1002
996
|
// packages/react/src/runtime/core.tsx
|
|
1003
997
|
var import_react9 = require("react");
|
|
1004
998
|
var import_react10 = require("@assistant-ui/react");
|
|
999
|
+
var import_client4 = require("@aomi-labs/client");
|
|
1005
1000
|
|
|
1006
1001
|
// packages/react/src/runtime/orchestrator.ts
|
|
1007
1002
|
var import_react6 = require("react");
|
|
1008
1003
|
|
|
1009
1004
|
// packages/react/src/runtime/session-manager.ts
|
|
1010
|
-
var
|
|
1005
|
+
var import_client3 = require("@aomi-labs/client");
|
|
1011
1006
|
var SessionManager = class {
|
|
1012
1007
|
constructor(clientFactory) {
|
|
1013
1008
|
this.clientFactory = clientFactory;
|
|
@@ -1016,7 +1011,7 @@ var SessionManager = class {
|
|
|
1016
1011
|
getOrCreate(threadId, opts) {
|
|
1017
1012
|
let session = this.sessions.get(threadId);
|
|
1018
1013
|
if (session) return session;
|
|
1019
|
-
session = new
|
|
1014
|
+
session = new import_client3.Session(this.clientFactory(), __spreadProps(__spreadValues({}, opts), {
|
|
1020
1015
|
sessionId: threadId
|
|
1021
1016
|
}));
|
|
1022
1017
|
this.sessions.set(threadId, session);
|
|
@@ -1195,16 +1190,13 @@ function useRuntimeOrchestrator(aomiClient, options) {
|
|
|
1195
1190
|
})
|
|
1196
1191
|
);
|
|
1197
1192
|
cleanups.push(
|
|
1198
|
-
session.on(
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
var _a2;
|
|
1206
|
-
return (_a2 = options.onWalletRequest) == null ? void 0 : _a2.call(options, req);
|
|
1207
|
-
})
|
|
1193
|
+
session.on(
|
|
1194
|
+
"wallet_requests_changed",
|
|
1195
|
+
(requests) => {
|
|
1196
|
+
var _a2;
|
|
1197
|
+
return (_a2 = options.onPendingRequestsChange) == null ? void 0 : _a2.call(options, requests);
|
|
1198
|
+
}
|
|
1199
|
+
)
|
|
1208
1200
|
);
|
|
1209
1201
|
cleanups.push(
|
|
1210
1202
|
session.on("title_changed", ({ title }) => {
|
|
@@ -1230,7 +1222,7 @@ function useRuntimeOrchestrator(aomiClient, options) {
|
|
|
1230
1222
|
);
|
|
1231
1223
|
const ensureInitialState = (0, import_react6.useCallback)(
|
|
1232
1224
|
async (threadId) => {
|
|
1233
|
-
var _a;
|
|
1225
|
+
var _a, _b;
|
|
1234
1226
|
if (pendingFetches.current.has(threadId)) return;
|
|
1235
1227
|
pendingFetches.current.add(threadId);
|
|
1236
1228
|
try {
|
|
@@ -1238,6 +1230,7 @@ function useRuntimeOrchestrator(aomiClient, options) {
|
|
|
1238
1230
|
const userState = (_a = options.getUserState) == null ? void 0 : _a.call(options);
|
|
1239
1231
|
if (userState) session.resolveUserState(userState);
|
|
1240
1232
|
await session.fetchCurrentState();
|
|
1233
|
+
(_b = options.onPendingRequestsChange) == null ? void 0 : _b.call(options, session.getPendingRequests());
|
|
1241
1234
|
if (threadContextRef.current.currentThreadId === threadId) {
|
|
1242
1235
|
setIsRunning(session.getIsProcessing());
|
|
1243
1236
|
}
|
|
@@ -1254,7 +1247,7 @@ function useRuntimeOrchestrator(aomiClient, options) {
|
|
|
1254
1247
|
);
|
|
1255
1248
|
const sendMessage = (0, import_react6.useCallback)(
|
|
1256
1249
|
async (text, threadId) => {
|
|
1257
|
-
var _a;
|
|
1250
|
+
var _a, _b;
|
|
1258
1251
|
const session = getSession(threadId);
|
|
1259
1252
|
const userState = (_a = options.getUserState) == null ? void 0 : _a.call(options);
|
|
1260
1253
|
if (userState) session.resolveUserState(userState);
|
|
@@ -1272,6 +1265,7 @@ function useRuntimeOrchestrator(aomiClient, options) {
|
|
|
1272
1265
|
lastActiveAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1273
1266
|
});
|
|
1274
1267
|
await session.sendAsync(text);
|
|
1268
|
+
(_b = options.onPendingRequestsChange) == null ? void 0 : _b.call(options, session.getPendingRequests());
|
|
1275
1269
|
},
|
|
1276
1270
|
[getSession]
|
|
1277
1271
|
);
|
|
@@ -1459,44 +1453,85 @@ function useWalletHandler({
|
|
|
1459
1453
|
getSession
|
|
1460
1454
|
}) {
|
|
1461
1455
|
const [pendingRequests, setPendingRequests] = (0, import_react8.useState)([]);
|
|
1462
|
-
const requestsRef = (0, import_react8.useRef)(
|
|
1463
|
-
const
|
|
1464
|
-
|
|
1465
|
-
|
|
1456
|
+
const requestsRef = (0, import_react8.useRef)(pendingRequests);
|
|
1457
|
+
const inFlightRequestSetRef = (0, import_react8.useRef)(/* @__PURE__ */ new Set());
|
|
1458
|
+
const suppressedRequestSetRef = (0, import_react8.useRef)(/* @__PURE__ */ new Set());
|
|
1459
|
+
const syncVisibleRequests = (0, import_react8.useCallback)(() => {
|
|
1460
|
+
setPendingRequests(
|
|
1461
|
+
requestsRef.current.filter(
|
|
1462
|
+
(request) => !suppressedRequestSetRef.current.has(request.id)
|
|
1463
|
+
)
|
|
1464
|
+
);
|
|
1466
1465
|
}, []);
|
|
1466
|
+
const setRequests = (0, import_react8.useCallback)((requests) => {
|
|
1467
|
+
const incomingIds = new Set(requests.map((request) => request.id));
|
|
1468
|
+
for (const id of suppressedRequestSetRef.current) {
|
|
1469
|
+
if (!incomingIds.has(id) && !inFlightRequestSetRef.current.has(id)) {
|
|
1470
|
+
suppressedRequestSetRef.current.delete(id);
|
|
1471
|
+
}
|
|
1472
|
+
}
|
|
1473
|
+
const preservedInFlight = requestsRef.current.filter(
|
|
1474
|
+
(request) => inFlightRequestSetRef.current.has(request.id) && !incomingIds.has(request.id)
|
|
1475
|
+
);
|
|
1476
|
+
requestsRef.current = [...requests, ...preservedInFlight];
|
|
1477
|
+
syncVisibleRequests();
|
|
1478
|
+
}, [syncVisibleRequests]);
|
|
1479
|
+
const startRequest = (0, import_react8.useCallback)((id) => {
|
|
1480
|
+
if (!requestsRef.current.some((request) => request.id === id)) {
|
|
1481
|
+
return;
|
|
1482
|
+
}
|
|
1483
|
+
inFlightRequestSetRef.current.add(id);
|
|
1484
|
+
suppressedRequestSetRef.current.add(id);
|
|
1485
|
+
syncVisibleRequests();
|
|
1486
|
+
}, [syncVisibleRequests]);
|
|
1467
1487
|
const resolveRequest = (0, import_react8.useCallback)(
|
|
1468
|
-
(id, result) => {
|
|
1488
|
+
async (id, result) => {
|
|
1469
1489
|
const session = getSession();
|
|
1470
1490
|
if (!session) {
|
|
1471
1491
|
console.error("[wallet-handler] No session available to resolve request");
|
|
1472
1492
|
return;
|
|
1473
1493
|
}
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1494
|
+
startRequest(id);
|
|
1495
|
+
try {
|
|
1496
|
+
await session.resolve(id, result);
|
|
1497
|
+
} catch (err) {
|
|
1477
1498
|
console.error("[wallet-handler] Failed to resolve request:", err);
|
|
1478
|
-
}
|
|
1499
|
+
} finally {
|
|
1500
|
+
requestsRef.current = requestsRef.current.filter(
|
|
1501
|
+
(request) => request.id !== id
|
|
1502
|
+
);
|
|
1503
|
+
inFlightRequestSetRef.current.delete(id);
|
|
1504
|
+
syncVisibleRequests();
|
|
1505
|
+
}
|
|
1479
1506
|
},
|
|
1480
|
-
[getSession]
|
|
1507
|
+
[getSession, startRequest, syncVisibleRequests]
|
|
1481
1508
|
);
|
|
1482
1509
|
const rejectRequest = (0, import_react8.useCallback)(
|
|
1483
|
-
(id, error) => {
|
|
1510
|
+
async (id, error) => {
|
|
1484
1511
|
const session = getSession();
|
|
1485
1512
|
if (!session) {
|
|
1486
1513
|
console.error("[wallet-handler] No session available to reject request");
|
|
1487
1514
|
return;
|
|
1488
1515
|
}
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1516
|
+
startRequest(id);
|
|
1517
|
+
try {
|
|
1518
|
+
await session.reject(id, error);
|
|
1519
|
+
} catch (err) {
|
|
1492
1520
|
console.error("[wallet-handler] Failed to reject request:", err);
|
|
1493
|
-
}
|
|
1521
|
+
} finally {
|
|
1522
|
+
requestsRef.current = requestsRef.current.filter(
|
|
1523
|
+
(request) => request.id !== id
|
|
1524
|
+
);
|
|
1525
|
+
inFlightRequestSetRef.current.delete(id);
|
|
1526
|
+
syncVisibleRequests();
|
|
1527
|
+
}
|
|
1494
1528
|
},
|
|
1495
|
-
[getSession]
|
|
1529
|
+
[getSession, startRequest, syncVisibleRequests]
|
|
1496
1530
|
);
|
|
1497
1531
|
return {
|
|
1498
1532
|
pendingRequests,
|
|
1499
|
-
|
|
1533
|
+
setRequests,
|
|
1534
|
+
startRequest,
|
|
1500
1535
|
resolveRequest,
|
|
1501
1536
|
rejectRequest
|
|
1502
1537
|
};
|
|
@@ -1530,11 +1565,7 @@ function AomiRuntimeCore({
|
|
|
1530
1565
|
cancelGeneration: orchestratorCancel,
|
|
1531
1566
|
aomiClientRef
|
|
1532
1567
|
} = useRuntimeOrchestrator(aomiClient, {
|
|
1533
|
-
getPublicKey: () =>
|
|
1534
|
-
var _a;
|
|
1535
|
-
const userState = getUserState();
|
|
1536
|
-
return userState.isConnected ? (_a = userState.address) != null ? _a : void 0 : void 0;
|
|
1537
|
-
},
|
|
1568
|
+
getPublicKey: () => import_client4.UserState.isConnected(getUserState()) ? import_client4.UserState.address(getUserState()) : void 0,
|
|
1538
1569
|
getUserState,
|
|
1539
1570
|
getApp: getCurrentThreadApp,
|
|
1540
1571
|
getApiKey: () => getControlState().apiKey,
|
|
@@ -1542,17 +1573,20 @@ function AomiRuntimeCore({
|
|
|
1542
1573
|
var _a;
|
|
1543
1574
|
return (_a = getControlState().clientId) != null ? _a : void 0;
|
|
1544
1575
|
},
|
|
1545
|
-
|
|
1576
|
+
onPendingRequestsChange: walletHandler.setRequests,
|
|
1546
1577
|
onEvent: (event) => eventContext.dispatch(event)
|
|
1547
1578
|
});
|
|
1548
1579
|
sessionManagerRef.current = sessionManager;
|
|
1549
1580
|
const walletSnapshot = (0, import_react9.useCallback)(
|
|
1550
|
-
(nextUser) =>
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1581
|
+
(nextUser) => {
|
|
1582
|
+
var _a;
|
|
1583
|
+
return {
|
|
1584
|
+
address: import_client4.UserState.address(nextUser),
|
|
1585
|
+
chain_id: import_client4.UserState.chainId(nextUser),
|
|
1586
|
+
is_connected: (_a = import_client4.UserState.isConnected(nextUser)) != null ? _a : false,
|
|
1587
|
+
ens_name: typeof nextUser.ens_name === "string" ? nextUser.ens_name : void 0
|
|
1588
|
+
};
|
|
1589
|
+
},
|
|
1556
1590
|
[getUserState]
|
|
1557
1591
|
);
|
|
1558
1592
|
const lastWalletStateRef = (0, import_react9.useRef)(walletSnapshot(getUserState()));
|
|
@@ -1561,7 +1595,7 @@ function AomiRuntimeCore({
|
|
|
1561
1595
|
const unsubscribe = onUserStateChange(async (newUser) => {
|
|
1562
1596
|
const nextWalletState = walletSnapshot(newUser);
|
|
1563
1597
|
const prevWalletState = lastWalletStateRef.current;
|
|
1564
|
-
if (prevWalletState.address === nextWalletState.address && prevWalletState.
|
|
1598
|
+
if (prevWalletState.address === nextWalletState.address && prevWalletState.chain_id === nextWalletState.chain_id && prevWalletState.is_connected === nextWalletState.is_connected && prevWalletState.ens_name === nextWalletState.ens_name) {
|
|
1565
1599
|
return;
|
|
1566
1600
|
}
|
|
1567
1601
|
lastWalletStateRef.current = nextWalletState;
|
|
@@ -1582,26 +1616,50 @@ function AomiRuntimeCore({
|
|
|
1582
1616
|
]);
|
|
1583
1617
|
const threadContextRef = (0, import_react9.useRef)(threadContext);
|
|
1584
1618
|
threadContextRef.current = threadContext;
|
|
1585
|
-
const
|
|
1586
|
-
(0, import_react9.
|
|
1587
|
-
|
|
1588
|
-
|
|
1619
|
+
const remoteThreadIdsRef = (0, import_react9.useRef)(/* @__PURE__ */ new Set());
|
|
1620
|
+
const warmedThreadIdsRef = (0, import_react9.useRef)(/* @__PURE__ */ new Set());
|
|
1621
|
+
const warmThread = (0, import_react9.useCallback)(
|
|
1622
|
+
async (threadId) => {
|
|
1623
|
+
if (!remoteThreadIdsRef.current.has(threadId) || warmedThreadIdsRef.current.has(threadId)) {
|
|
1624
|
+
return;
|
|
1625
|
+
}
|
|
1626
|
+
const userState = getUserState();
|
|
1627
|
+
await aomiClientRef.current.createThread(
|
|
1628
|
+
threadId,
|
|
1629
|
+
import_client4.UserState.isConnected(userState) ? import_client4.UserState.address(userState) : void 0
|
|
1630
|
+
);
|
|
1631
|
+
warmedThreadIdsRef.current.add(threadId);
|
|
1632
|
+
},
|
|
1633
|
+
[aomiClientRef, getUserState]
|
|
1634
|
+
);
|
|
1589
1635
|
(0, import_react9.useEffect)(() => {
|
|
1590
1636
|
const unsubscribe = eventContext.subscribe(
|
|
1591
1637
|
"user_state_request",
|
|
1592
1638
|
() => {
|
|
1639
|
+
var _a, _b, _c;
|
|
1640
|
+
const session = (_b = (_a = sessionManagerRef.current) == null ? void 0 : _a.get(threadContext.currentThreadId)) != null ? _b : getSession(threadContext.currentThreadId);
|
|
1593
1641
|
eventContext.sendOutboundSystem({
|
|
1594
1642
|
type: "user_state_response",
|
|
1595
1643
|
sessionId: threadContext.currentThreadId,
|
|
1596
|
-
payload: getUserState()
|
|
1644
|
+
payload: (_c = session.getUserState()) != null ? _c : getUserState()
|
|
1597
1645
|
});
|
|
1598
1646
|
}
|
|
1599
1647
|
);
|
|
1600
1648
|
return unsubscribe;
|
|
1601
|
-
}, [eventContext, threadContext.currentThreadId, getUserState]);
|
|
1649
|
+
}, [eventContext, threadContext.currentThreadId, getSession, getUserState]);
|
|
1602
1650
|
(0, import_react9.useEffect)(() => {
|
|
1603
|
-
|
|
1604
|
-
|
|
1651
|
+
const threadId = threadContext.currentThreadId;
|
|
1652
|
+
let cancelled = false;
|
|
1653
|
+
void (async () => {
|
|
1654
|
+
await warmThread(threadId);
|
|
1655
|
+
if (!cancelled) {
|
|
1656
|
+
await ensureInitialState(threadId);
|
|
1657
|
+
}
|
|
1658
|
+
})();
|
|
1659
|
+
return () => {
|
|
1660
|
+
cancelled = true;
|
|
1661
|
+
};
|
|
1662
|
+
}, [ensureInitialState, threadContext.currentThreadId, warmThread]);
|
|
1605
1663
|
(0, import_react9.useEffect)(() => {
|
|
1606
1664
|
const threadId = threadContext.currentThreadId;
|
|
1607
1665
|
const currentMeta = threadContext.getThreadMetadata(threadId);
|
|
@@ -1617,16 +1675,22 @@ function AomiRuntimeCore({
|
|
|
1617
1675
|
threadContext.currentThreadId
|
|
1618
1676
|
);
|
|
1619
1677
|
(0, import_react9.useEffect)(() => {
|
|
1620
|
-
const userAddress =
|
|
1621
|
-
if (!userAddress)
|
|
1678
|
+
const userAddress = import_client4.UserState.isConnected(user) ? import_client4.UserState.address(user) : void 0;
|
|
1679
|
+
if (!userAddress) {
|
|
1680
|
+
remoteThreadIdsRef.current.clear();
|
|
1681
|
+
warmedThreadIdsRef.current.clear();
|
|
1682
|
+
return;
|
|
1683
|
+
}
|
|
1622
1684
|
const fetchThreadList = async () => {
|
|
1623
1685
|
var _a, _b, _c;
|
|
1624
1686
|
try {
|
|
1625
1687
|
const threadList = await aomiClientRef.current.listThreads(userAddress);
|
|
1626
1688
|
const currentContext = threadContextRef.current;
|
|
1689
|
+
const remoteThreadIds = /* @__PURE__ */ new Set();
|
|
1627
1690
|
const newMetadata = new Map(currentContext.allThreadsMetadata);
|
|
1628
1691
|
let maxChatNum = currentContext.threadCnt;
|
|
1629
1692
|
for (const thread of threadList) {
|
|
1693
|
+
remoteThreadIds.add(thread.session_id);
|
|
1630
1694
|
const rawTitle = (_a = thread.title) != null ? _a : "";
|
|
1631
1695
|
const title = isPlaceholderTitle(rawTitle) ? "" : rawTitle;
|
|
1632
1696
|
const lastActive = ((_b = newMetadata.get(thread.session_id)) == null ? void 0 : _b.lastActiveAt) || (/* @__PURE__ */ new Date()).toISOString();
|
|
@@ -1645,16 +1709,26 @@ function AomiRuntimeCore({
|
|
|
1645
1709
|
}
|
|
1646
1710
|
}
|
|
1647
1711
|
}
|
|
1712
|
+
remoteThreadIdsRef.current = remoteThreadIds;
|
|
1713
|
+
warmedThreadIdsRef.current = new Set(
|
|
1714
|
+
Array.from(warmedThreadIdsRef.current).filter(
|
|
1715
|
+
(threadId) => remoteThreadIds.has(threadId)
|
|
1716
|
+
)
|
|
1717
|
+
);
|
|
1648
1718
|
currentContext.setThreadMetadata(newMetadata);
|
|
1649
1719
|
if (maxChatNum > currentContext.threadCnt) {
|
|
1650
1720
|
currentContext.setThreadCnt(maxChatNum);
|
|
1651
1721
|
}
|
|
1722
|
+
if (remoteThreadIds.has(currentContext.currentThreadId)) {
|
|
1723
|
+
await warmThread(currentContext.currentThreadId);
|
|
1724
|
+
await ensureInitialState(currentContext.currentThreadId);
|
|
1725
|
+
}
|
|
1652
1726
|
} catch (error) {
|
|
1653
1727
|
console.error("Failed to fetch thread list:", error);
|
|
1654
1728
|
}
|
|
1655
1729
|
};
|
|
1656
1730
|
void fetchThreadList();
|
|
1657
|
-
}, [user
|
|
1731
|
+
}, [user, aomiClientRef, ensureInitialState, warmThread]);
|
|
1658
1732
|
const threadListAdapter = (0, import_react9.useMemo)(
|
|
1659
1733
|
() => buildThreadListAdapter({
|
|
1660
1734
|
aomiClientRef,
|
|
@@ -1803,9 +1877,7 @@ function AomiRuntimeCore({
|
|
|
1803
1877
|
clearAllNotifications: notificationContext.clearAll,
|
|
1804
1878
|
// Wallet API
|
|
1805
1879
|
pendingWalletRequests: walletHandler.pendingRequests,
|
|
1806
|
-
startWalletRequest:
|
|
1807
|
-
},
|
|
1808
|
-
// No-op: ClientSession manages processing state
|
|
1880
|
+
startWalletRequest: walletHandler.startRequest,
|
|
1809
1881
|
resolveWalletRequest: walletHandler.resolveRequest,
|
|
1810
1882
|
rejectWalletRequest: walletHandler.rejectRequest,
|
|
1811
1883
|
// Event API
|
|
@@ -1842,7 +1914,7 @@ function AomiRuntimeProvider({
|
|
|
1842
1914
|
children,
|
|
1843
1915
|
backendUrl = "http://localhost:8080"
|
|
1844
1916
|
}) {
|
|
1845
|
-
const aomiClient = (0, import_react11.useMemo)(() => new
|
|
1917
|
+
const aomiClient = (0, import_react11.useMemo)(() => new import_client5.AomiClient({ baseUrl: backendUrl }), [backendUrl]);
|
|
1846
1918
|
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ThreadContextProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(NotificationContextProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(UserContextProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(AomiRuntimeInner, { aomiClient, children }) }) }) });
|
|
1847
1919
|
}
|
|
1848
1920
|
function AomiRuntimeInner({
|
|
@@ -1857,7 +1929,7 @@ function AomiRuntimeInner({
|
|
|
1857
1929
|
{
|
|
1858
1930
|
aomiClient,
|
|
1859
1931
|
sessionId: threadContext.currentThreadId,
|
|
1860
|
-
publicKey:
|
|
1932
|
+
publicKey: import_client5.UserState.isConnected(user) ? (_a = import_client5.UserState.address(user)) != null ? _a : void 0 : void 0,
|
|
1861
1933
|
getThreadMetadata: threadContext.getThreadMetadata,
|
|
1862
1934
|
updateThreadMetadata: threadContext.updateThreadMetadata,
|
|
1863
1935
|
children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|