@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 +77 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -6
- package/dist/index.d.ts +8 -6
- package/dist/index.js +77 -22
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -135,10 +135,12 @@ type WalletHandlerApi = {
|
|
|
135
135
|
pendingRequests: WalletRequest[];
|
|
136
136
|
/** Replace pending requests with the session's authoritative snapshot. */
|
|
137
137
|
setRequests: (requests: WalletRequest[]) => void;
|
|
138
|
+
/** Mark a request as in-flight so it is not replayed while awaiting backend ack. */
|
|
139
|
+
startRequest: (id: string) => void;
|
|
138
140
|
/** Complete a request successfully — sends response to backend via ClientSession */
|
|
139
|
-
resolveRequest: (id: string, result: WalletRequestResult) => void
|
|
141
|
+
resolveRequest: (id: string, result: WalletRequestResult) => Promise<void>;
|
|
140
142
|
/** Fail a request — sends error to backend via ClientSession */
|
|
141
|
-
rejectRequest: (id: string, error?: string) => void
|
|
143
|
+
rejectRequest: (id: string, error?: string) => Promise<void>;
|
|
142
144
|
};
|
|
143
145
|
declare function useWalletHandler({ getSession, }: WalletHandlerConfig): WalletHandlerApi;
|
|
144
146
|
|
|
@@ -193,10 +195,10 @@ type AomiRuntimeApi = {
|
|
|
193
195
|
pendingWalletRequests: WalletRequest[];
|
|
194
196
|
/** Mark a wallet request as being processed */
|
|
195
197
|
startWalletRequest: (id: string) => void;
|
|
196
|
-
/** Complete a wallet request
|
|
197
|
-
resolveWalletRequest: (id: string, result: WalletRequestResult) => void
|
|
198
|
-
/** Fail a wallet request
|
|
199
|
-
rejectWalletRequest: (id: string, error?: string) => void
|
|
198
|
+
/** Complete a wallet request after the backend acknowledges the response */
|
|
199
|
+
resolveWalletRequest: (id: string, result: WalletRequestResult) => Promise<void>;
|
|
200
|
+
/** Fail a wallet request after the backend acknowledges the error */
|
|
201
|
+
rejectWalletRequest: (id: string, error?: string) => Promise<void>;
|
|
200
202
|
/** Subscribe to inbound events by type. Returns unsubscribe function. */
|
|
201
203
|
subscribe: (type: string, callback: EventSubscriber) => () => void;
|
|
202
204
|
/** Send a system command to the backend */
|
package/dist/index.d.ts
CHANGED
|
@@ -135,10 +135,12 @@ type WalletHandlerApi = {
|
|
|
135
135
|
pendingRequests: WalletRequest[];
|
|
136
136
|
/** Replace pending requests with the session's authoritative snapshot. */
|
|
137
137
|
setRequests: (requests: WalletRequest[]) => void;
|
|
138
|
+
/** Mark a request as in-flight so it is not replayed while awaiting backend ack. */
|
|
139
|
+
startRequest: (id: string) => void;
|
|
138
140
|
/** Complete a request successfully — sends response to backend via ClientSession */
|
|
139
|
-
resolveRequest: (id: string, result: WalletRequestResult) => void
|
|
141
|
+
resolveRequest: (id: string, result: WalletRequestResult) => Promise<void>;
|
|
140
142
|
/** Fail a request — sends error to backend via ClientSession */
|
|
141
|
-
rejectRequest: (id: string, error?: string) => void
|
|
143
|
+
rejectRequest: (id: string, error?: string) => Promise<void>;
|
|
142
144
|
};
|
|
143
145
|
declare function useWalletHandler({ getSession, }: WalletHandlerConfig): WalletHandlerApi;
|
|
144
146
|
|
|
@@ -193,10 +195,10 @@ type AomiRuntimeApi = {
|
|
|
193
195
|
pendingWalletRequests: WalletRequest[];
|
|
194
196
|
/** Mark a wallet request as being processed */
|
|
195
197
|
startWalletRequest: (id: string) => void;
|
|
196
|
-
/** Complete a wallet request
|
|
197
|
-
resolveWalletRequest: (id: string, result: WalletRequestResult) => void
|
|
198
|
-
/** Fail a wallet request
|
|
199
|
-
rejectWalletRequest: (id: string, error?: string) => void
|
|
198
|
+
/** Complete a wallet request after the backend acknowledges the response */
|
|
199
|
+
resolveWalletRequest: (id: string, result: WalletRequestResult) => Promise<void>;
|
|
200
|
+
/** Fail a wallet request after the backend acknowledges the error */
|
|
201
|
+
rejectWalletRequest: (id: string, error?: string) => Promise<void>;
|
|
200
202
|
/** Subscribe to inbound events by type. Returns unsubscribe function. */
|
|
201
203
|
subscribe: (type: string, callback: EventSubscriber) => () => void;
|
|
202
204
|
/** Send a system command to the backend */
|
package/dist/index.js
CHANGED
|
@@ -1143,14 +1143,28 @@ function useRuntimeOrchestrator(aomiClient, options) {
|
|
|
1143
1143
|
(threadId) => {
|
|
1144
1144
|
var _a, _b, _c, _d, _e;
|
|
1145
1145
|
const manager = sessionManagerRef.current;
|
|
1146
|
+
const nextApp = options.getApp();
|
|
1147
|
+
const nextPublicKey = (_a = options.getPublicKey) == null ? void 0 : _a.call(options);
|
|
1148
|
+
const nextApiKey = (_c = (_b = options.getApiKey) == null ? void 0 : _b.call(options)) != null ? _c : void 0;
|
|
1149
|
+
const nextClientId = (_d = options.getClientId) == null ? void 0 : _d.call(options);
|
|
1150
|
+
const nextUserState = (_e = options.getUserState) == null ? void 0 : _e.call(options);
|
|
1146
1151
|
const existing = manager.get(threadId);
|
|
1147
|
-
if (existing)
|
|
1152
|
+
if (existing) {
|
|
1153
|
+
existing.syncRuntimeOptions({
|
|
1154
|
+
app: nextApp,
|
|
1155
|
+
publicKey: nextPublicKey,
|
|
1156
|
+
apiKey: nextApiKey,
|
|
1157
|
+
clientId: nextClientId,
|
|
1158
|
+
userState: nextUserState
|
|
1159
|
+
});
|
|
1160
|
+
return existing;
|
|
1161
|
+
}
|
|
1148
1162
|
const session = manager.getOrCreate(threadId, {
|
|
1149
|
-
app:
|
|
1150
|
-
publicKey:
|
|
1151
|
-
apiKey:
|
|
1152
|
-
clientId:
|
|
1153
|
-
userState:
|
|
1163
|
+
app: nextApp,
|
|
1164
|
+
publicKey: nextPublicKey,
|
|
1165
|
+
apiKey: nextApiKey,
|
|
1166
|
+
clientId: nextClientId,
|
|
1167
|
+
userState: nextUserState
|
|
1154
1168
|
});
|
|
1155
1169
|
const cleanups = [];
|
|
1156
1170
|
cleanups.push(
|
|
@@ -1442,41 +1456,84 @@ function useWalletHandler({
|
|
|
1442
1456
|
}) {
|
|
1443
1457
|
const [pendingRequests, setPendingRequests] = useState5([]);
|
|
1444
1458
|
const requestsRef = useRef6(pendingRequests);
|
|
1445
|
-
const
|
|
1446
|
-
|
|
1447
|
-
|
|
1459
|
+
const inFlightRequestSetRef = useRef6(/* @__PURE__ */ new Set());
|
|
1460
|
+
const suppressedRequestSetRef = useRef6(/* @__PURE__ */ new Set());
|
|
1461
|
+
const syncVisibleRequests = useCallback6(() => {
|
|
1462
|
+
setPendingRequests(
|
|
1463
|
+
requestsRef.current.filter(
|
|
1464
|
+
(request) => !suppressedRequestSetRef.current.has(request.id)
|
|
1465
|
+
)
|
|
1466
|
+
);
|
|
1448
1467
|
}, []);
|
|
1468
|
+
const setRequests = useCallback6((requests) => {
|
|
1469
|
+
const incomingIds = new Set(requests.map((request) => request.id));
|
|
1470
|
+
for (const id of suppressedRequestSetRef.current) {
|
|
1471
|
+
if (!incomingIds.has(id) && !inFlightRequestSetRef.current.has(id)) {
|
|
1472
|
+
suppressedRequestSetRef.current.delete(id);
|
|
1473
|
+
}
|
|
1474
|
+
}
|
|
1475
|
+
const preservedInFlight = requestsRef.current.filter(
|
|
1476
|
+
(request) => inFlightRequestSetRef.current.has(request.id) && !incomingIds.has(request.id)
|
|
1477
|
+
);
|
|
1478
|
+
requestsRef.current = [...requests, ...preservedInFlight];
|
|
1479
|
+
syncVisibleRequests();
|
|
1480
|
+
}, [syncVisibleRequests]);
|
|
1481
|
+
const startRequest = useCallback6((id) => {
|
|
1482
|
+
if (!requestsRef.current.some((request) => request.id === id)) {
|
|
1483
|
+
return;
|
|
1484
|
+
}
|
|
1485
|
+
inFlightRequestSetRef.current.add(id);
|
|
1486
|
+
suppressedRequestSetRef.current.add(id);
|
|
1487
|
+
syncVisibleRequests();
|
|
1488
|
+
}, [syncVisibleRequests]);
|
|
1449
1489
|
const resolveRequest = useCallback6(
|
|
1450
|
-
(id, result) => {
|
|
1490
|
+
async (id, result) => {
|
|
1451
1491
|
const session = getSession();
|
|
1452
1492
|
if (!session) {
|
|
1453
1493
|
console.error("[wallet-handler] No session available to resolve request");
|
|
1454
1494
|
return;
|
|
1455
1495
|
}
|
|
1456
|
-
|
|
1457
|
-
|
|
1496
|
+
startRequest(id);
|
|
1497
|
+
try {
|
|
1498
|
+
await session.resolve(id, result);
|
|
1499
|
+
} catch (err) {
|
|
1458
1500
|
console.error("[wallet-handler] Failed to resolve request:", err);
|
|
1459
|
-
}
|
|
1501
|
+
} finally {
|
|
1502
|
+
requestsRef.current = requestsRef.current.filter(
|
|
1503
|
+
(request) => request.id !== id
|
|
1504
|
+
);
|
|
1505
|
+
inFlightRequestSetRef.current.delete(id);
|
|
1506
|
+
syncVisibleRequests();
|
|
1507
|
+
}
|
|
1460
1508
|
},
|
|
1461
|
-
[getSession,
|
|
1509
|
+
[getSession, startRequest, syncVisibleRequests]
|
|
1462
1510
|
);
|
|
1463
1511
|
const rejectRequest = useCallback6(
|
|
1464
|
-
(id, error) => {
|
|
1512
|
+
async (id, error) => {
|
|
1465
1513
|
const session = getSession();
|
|
1466
1514
|
if (!session) {
|
|
1467
1515
|
console.error("[wallet-handler] No session available to reject request");
|
|
1468
1516
|
return;
|
|
1469
1517
|
}
|
|
1470
|
-
|
|
1471
|
-
|
|
1518
|
+
startRequest(id);
|
|
1519
|
+
try {
|
|
1520
|
+
await session.reject(id, error);
|
|
1521
|
+
} catch (err) {
|
|
1472
1522
|
console.error("[wallet-handler] Failed to reject request:", err);
|
|
1473
|
-
}
|
|
1523
|
+
} finally {
|
|
1524
|
+
requestsRef.current = requestsRef.current.filter(
|
|
1525
|
+
(request) => request.id !== id
|
|
1526
|
+
);
|
|
1527
|
+
inFlightRequestSetRef.current.delete(id);
|
|
1528
|
+
syncVisibleRequests();
|
|
1529
|
+
}
|
|
1474
1530
|
},
|
|
1475
|
-
[getSession,
|
|
1531
|
+
[getSession, startRequest, syncVisibleRequests]
|
|
1476
1532
|
);
|
|
1477
1533
|
return {
|
|
1478
1534
|
pendingRequests,
|
|
1479
1535
|
setRequests,
|
|
1536
|
+
startRequest,
|
|
1480
1537
|
resolveRequest,
|
|
1481
1538
|
rejectRequest
|
|
1482
1539
|
};
|
|
@@ -1822,9 +1879,7 @@ function AomiRuntimeCore({
|
|
|
1822
1879
|
clearAllNotifications: notificationContext.clearAll,
|
|
1823
1880
|
// Wallet API
|
|
1824
1881
|
pendingWalletRequests: walletHandler.pendingRequests,
|
|
1825
|
-
startWalletRequest:
|
|
1826
|
-
},
|
|
1827
|
-
// No-op: ClientSession manages processing state
|
|
1882
|
+
startWalletRequest: walletHandler.startRequest,
|
|
1828
1883
|
resolveWalletRequest: walletHandler.resolveRequest,
|
|
1829
1884
|
rejectWalletRequest: walletHandler.rejectRequest,
|
|
1830
1885
|
// Event API
|