@aomi-labs/react 0.3.10 → 0.3.12

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
@@ -1155,14 +1155,28 @@ function useRuntimeOrchestrator(aomiClient, options) {
1155
1155
  (threadId) => {
1156
1156
  var _a, _b, _c, _d, _e;
1157
1157
  const manager = sessionManagerRef.current;
1158
+ const nextApp = options.getApp();
1159
+ const nextPublicKey = (_a = options.getPublicKey) == null ? void 0 : _a.call(options);
1160
+ const nextApiKey = (_c = (_b = options.getApiKey) == null ? void 0 : _b.call(options)) != null ? _c : void 0;
1161
+ const nextClientId = (_d = options.getClientId) == null ? void 0 : _d.call(options);
1162
+ const nextUserState = (_e = options.getUserState) == null ? void 0 : _e.call(options);
1158
1163
  const existing = manager.get(threadId);
1159
- if (existing) return existing;
1164
+ if (existing) {
1165
+ existing.syncRuntimeOptions({
1166
+ app: nextApp,
1167
+ publicKey: nextPublicKey,
1168
+ apiKey: nextApiKey,
1169
+ clientId: nextClientId,
1170
+ userState: nextUserState
1171
+ });
1172
+ return existing;
1173
+ }
1160
1174
  const session = manager.getOrCreate(threadId, {
1161
- app: options.getApp(),
1162
- publicKey: (_a = options.getPublicKey) == null ? void 0 : _a.call(options),
1163
- apiKey: (_c = (_b = options.getApiKey) == null ? void 0 : _b.call(options)) != null ? _c : void 0,
1164
- clientId: (_d = options.getClientId) == null ? void 0 : _d.call(options),
1165
- userState: (_e = options.getUserState) == null ? void 0 : _e.call(options)
1175
+ app: nextApp,
1176
+ publicKey: nextPublicKey,
1177
+ apiKey: nextApiKey,
1178
+ clientId: nextClientId,
1179
+ userState: nextUserState
1166
1180
  });
1167
1181
  const cleanups = [];
1168
1182
  cleanups.push(
@@ -1454,41 +1468,84 @@ function useWalletHandler({
1454
1468
  }) {
1455
1469
  const [pendingRequests, setPendingRequests] = (0, import_react8.useState)([]);
1456
1470
  const requestsRef = (0, import_react8.useRef)(pendingRequests);
1457
- const setRequests = (0, import_react8.useCallback)((requests) => {
1458
- requestsRef.current = [...requests];
1459
- setPendingRequests(requestsRef.current);
1471
+ const inFlightRequestSetRef = (0, import_react8.useRef)(/* @__PURE__ */ new Set());
1472
+ const suppressedRequestSetRef = (0, import_react8.useRef)(/* @__PURE__ */ new Set());
1473
+ const syncVisibleRequests = (0, import_react8.useCallback)(() => {
1474
+ setPendingRequests(
1475
+ requestsRef.current.filter(
1476
+ (request) => !suppressedRequestSetRef.current.has(request.id)
1477
+ )
1478
+ );
1460
1479
  }, []);
1480
+ const setRequests = (0, import_react8.useCallback)((requests) => {
1481
+ const incomingIds = new Set(requests.map((request) => request.id));
1482
+ for (const id of suppressedRequestSetRef.current) {
1483
+ if (!incomingIds.has(id) && !inFlightRequestSetRef.current.has(id)) {
1484
+ suppressedRequestSetRef.current.delete(id);
1485
+ }
1486
+ }
1487
+ const preservedInFlight = requestsRef.current.filter(
1488
+ (request) => inFlightRequestSetRef.current.has(request.id) && !incomingIds.has(request.id)
1489
+ );
1490
+ requestsRef.current = [...requests, ...preservedInFlight];
1491
+ syncVisibleRequests();
1492
+ }, [syncVisibleRequests]);
1493
+ const startRequest = (0, import_react8.useCallback)((id) => {
1494
+ if (!requestsRef.current.some((request) => request.id === id)) {
1495
+ return;
1496
+ }
1497
+ inFlightRequestSetRef.current.add(id);
1498
+ suppressedRequestSetRef.current.add(id);
1499
+ syncVisibleRequests();
1500
+ }, [syncVisibleRequests]);
1461
1501
  const resolveRequest = (0, import_react8.useCallback)(
1462
- (id, result) => {
1502
+ async (id, result) => {
1463
1503
  const session = getSession();
1464
1504
  if (!session) {
1465
1505
  console.error("[wallet-handler] No session available to resolve request");
1466
1506
  return;
1467
1507
  }
1468
- setRequests(requestsRef.current.filter((request) => request.id !== id));
1469
- void session.resolve(id, result).catch((err) => {
1508
+ startRequest(id);
1509
+ try {
1510
+ await session.resolve(id, result);
1511
+ } catch (err) {
1470
1512
  console.error("[wallet-handler] Failed to resolve request:", err);
1471
- });
1513
+ } finally {
1514
+ requestsRef.current = requestsRef.current.filter(
1515
+ (request) => request.id !== id
1516
+ );
1517
+ inFlightRequestSetRef.current.delete(id);
1518
+ syncVisibleRequests();
1519
+ }
1472
1520
  },
1473
- [getSession, setRequests]
1521
+ [getSession, startRequest, syncVisibleRequests]
1474
1522
  );
1475
1523
  const rejectRequest = (0, import_react8.useCallback)(
1476
- (id, error) => {
1524
+ async (id, error) => {
1477
1525
  const session = getSession();
1478
1526
  if (!session) {
1479
1527
  console.error("[wallet-handler] No session available to reject request");
1480
1528
  return;
1481
1529
  }
1482
- setRequests(requestsRef.current.filter((request) => request.id !== id));
1483
- void session.reject(id, error).catch((err) => {
1530
+ startRequest(id);
1531
+ try {
1532
+ await session.reject(id, error);
1533
+ } catch (err) {
1484
1534
  console.error("[wallet-handler] Failed to reject request:", err);
1485
- });
1535
+ } finally {
1536
+ requestsRef.current = requestsRef.current.filter(
1537
+ (request) => request.id !== id
1538
+ );
1539
+ inFlightRequestSetRef.current.delete(id);
1540
+ syncVisibleRequests();
1541
+ }
1486
1542
  },
1487
- [getSession, setRequests]
1543
+ [getSession, startRequest, syncVisibleRequests]
1488
1544
  );
1489
1545
  return {
1490
1546
  pendingRequests,
1491
1547
  setRequests,
1548
+ startRequest,
1492
1549
  resolveRequest,
1493
1550
  rejectRequest
1494
1551
  };
@@ -1834,9 +1891,7 @@ function AomiRuntimeCore({
1834
1891
  clearAllNotifications: notificationContext.clearAll,
1835
1892
  // Wallet API
1836
1893
  pendingWalletRequests: walletHandler.pendingRequests,
1837
- startWalletRequest: () => {
1838
- },
1839
- // No-op: ClientSession manages processing state
1894
+ startWalletRequest: walletHandler.startRequest,
1840
1895
  resolveWalletRequest: walletHandler.resolveRequest,
1841
1896
  rejectWalletRequest: walletHandler.rejectRequest,
1842
1897
  // Event API