@aomi-labs/react 0.3.12 → 0.3.14
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 +177 -76
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +35 -9
- package/dist/index.d.ts +35 -9
- package/dist/index.js +149 -47
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AomiClient, Session, WalletRequest,
|
|
2
|
-
export { AomiChatResponse, AomiClient, AomiClientOptions, AomiCreateThreadResponse, AomiInterruptResponse, AomiMessage, AomiSSEEvent, AomiStateResponse, AomiSystemEvent, AomiSystemResponse, AomiThread, UserState, WalletEip712Payload, WalletRequest, WalletTxPayload, toViemSignTypedDataArgs } from '@aomi-labs/client';
|
|
1
|
+
import { AomiClient, SessionOptions, Session, UserState, WalletRequest, WalletRequestResult, AomiSimulateResponse } from '@aomi-labs/client';
|
|
2
|
+
export { AomiChatResponse, AomiClient, AomiClientOptions, AomiCreateThreadResponse, AomiInterruptResponse, AomiMessage, AomiSSEEvent, AomiStateResponse, AomiSystemEvent, AomiSystemResponse, AomiThread, DISABLED_PROVIDER_STATE, MAX_AUTO_FEE_WEI, UserState, WalletEip712Payload, WalletRequest, WalletRequestResult, WalletTxPayload, aaModeFromExecutionKind, appendFeeCallToPayload, buildFeeAAWalletCall, executeWalletCalls, hydrateTxPayloadFromUserState, normalizeSimulatedFee, parseChainId, toAAWalletCall, toAAWalletCalls, toViemSignTypedDataArgs } from '@aomi-labs/client';
|
|
3
3
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
4
|
import { ReactNode, SetStateAction } from 'react';
|
|
5
5
|
import { ThreadMessageLike } from '@assistant-ui/react';
|
|
@@ -11,6 +11,25 @@ type AomiRuntimeProviderProps = {
|
|
|
11
11
|
};
|
|
12
12
|
declare function AomiRuntimeProvider({ children, backendUrl, }: Readonly<AomiRuntimeProviderProps>): react_jsx_runtime.JSX.Element;
|
|
13
13
|
|
|
14
|
+
declare class SessionManager {
|
|
15
|
+
private readonly clientFactory;
|
|
16
|
+
private sessions;
|
|
17
|
+
constructor(clientFactory: () => AomiClient);
|
|
18
|
+
getOrCreate(threadId: string, opts: Omit<SessionOptions, "sessionId">): Session;
|
|
19
|
+
get(threadId: string): Session | undefined;
|
|
20
|
+
forEach(callback: (session: Session, threadId: string) => void): void;
|
|
21
|
+
close(threadId: string): void;
|
|
22
|
+
closeAll(): void;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
type RuntimeUserStateProviderProps = {
|
|
26
|
+
children: ReactNode;
|
|
27
|
+
sessionManager: SessionManager;
|
|
28
|
+
getUserState: () => UserState;
|
|
29
|
+
onUserStateChange: (callback: (user: UserState) => void) => () => void;
|
|
30
|
+
};
|
|
31
|
+
declare function RuntimeUserStateProvider({ children, sessionManager, getUserState, onUserStateChange, }: RuntimeUserStateProviderProps): react_jsx_runtime.JSX.Element;
|
|
32
|
+
|
|
14
33
|
type ThreadContext = {
|
|
15
34
|
currentThreadId: string;
|
|
16
35
|
setCurrentThreadId: (id: string) => void;
|
|
@@ -121,11 +140,6 @@ declare function NotificationContextProvider({ children, }: NotificationContextP
|
|
|
121
140
|
|
|
122
141
|
type WalletRequestKind = "transaction" | "eip712_sign";
|
|
123
142
|
type WalletRequestStatus = "pending" | "processing";
|
|
124
|
-
type WalletRequestResult = {
|
|
125
|
-
txHash?: string;
|
|
126
|
-
signature?: string;
|
|
127
|
-
amount?: string;
|
|
128
|
-
};
|
|
129
143
|
type WalletHandlerConfig = {
|
|
130
144
|
/** Get the ClientSession for the current thread. */
|
|
131
145
|
getSession: () => Session | undefined;
|
|
@@ -193,12 +207,24 @@ type AomiRuntimeApi = {
|
|
|
193
207
|
clearAllNotifications: () => void;
|
|
194
208
|
/** All queued wallet requests (tx + eip712 signing) */
|
|
195
209
|
pendingWalletRequests: WalletRequest[];
|
|
196
|
-
/** Mark a wallet request as
|
|
210
|
+
/** Mark a wallet request as in-flight — suppresses it from the pending list until acked */
|
|
197
211
|
startWalletRequest: (id: string) => void;
|
|
198
212
|
/** Complete a wallet request after the backend acknowledges the response */
|
|
199
213
|
resolveWalletRequest: (id: string, result: WalletRequestResult) => Promise<void>;
|
|
200
214
|
/** Fail a wallet request after the backend acknowledges the error */
|
|
201
215
|
rejectWalletRequest: (id: string, error?: string) => Promise<void>;
|
|
216
|
+
/** Simulate a batch against the current thread session context. */
|
|
217
|
+
simulateBatchTransactions: (transactions: Array<{
|
|
218
|
+
to: string;
|
|
219
|
+
value?: string;
|
|
220
|
+
data?: string;
|
|
221
|
+
label?: string;
|
|
222
|
+
chain_id?: number;
|
|
223
|
+
chainId?: number;
|
|
224
|
+
}>, options?: {
|
|
225
|
+
from?: string;
|
|
226
|
+
chainId?: number;
|
|
227
|
+
}) => Promise<AomiSimulateResponse["result"]>;
|
|
202
228
|
/** Subscribe to inbound events by type. Returns unsubscribe function. */
|
|
203
229
|
subscribe: (type: string, callback: EventSubscriber) => () => void;
|
|
204
230
|
/** Send a system command to the backend */
|
|
@@ -380,4 +406,4 @@ type ControlContextProviderProps = {
|
|
|
380
406
|
};
|
|
381
407
|
declare function ControlContextProvider({ children, aomiClient, sessionId, publicKey, getThreadMetadata, updateThreadMetadata, }: ControlContextProviderProps): react_jsx_runtime.JSX.Element;
|
|
382
408
|
|
|
383
|
-
export { type AomiRuntimeApi, AomiRuntimeProvider, type AomiRuntimeProviderProps, type ChainInfo, type ControlContextApi, ControlContextProvider, type ControlContextProviderProps, type ControlState, type EventContext, EventContextProvider, type EventContextProviderProps, type EventSubscriber, type InboundEvent, type Notification$1 as Notification, type NotificationApi, NotificationContextProvider, type NotificationContextProviderProps, type NotificationContextApi as NotificationContextValue, type NotificationHandlerConfig, type NotificationType, type SSEStatus, SUPPORTED_CHAINS, type NotificationData as ShowNotificationParams, type StoredProviderKey, type ThreadContext, ThreadContextProvider, type ThreadControlState, type ThreadMetadata, type UserConfig, UserContextProvider, type WalletHandlerApi, type WalletHandlerConfig, type WalletRequestKind, type
|
|
409
|
+
export { type AomiRuntimeApi, AomiRuntimeProvider, type AomiRuntimeProviderProps, type ChainInfo, type ControlContextApi, ControlContextProvider, type ControlContextProviderProps, type ControlState, type EventContext, EventContextProvider, type EventContextProviderProps, type EventSubscriber, type InboundEvent, type Notification$1 as Notification, type NotificationApi, NotificationContextProvider, type NotificationContextProviderProps, type NotificationContextApi as NotificationContextValue, type NotificationHandlerConfig, type NotificationType, RuntimeUserStateProvider, type SSEStatus, SUPPORTED_CHAINS, type NotificationData as ShowNotificationParams, type StoredProviderKey, type ThreadContext, ThreadContextProvider, type ThreadControlState, type ThreadMetadata, type UserConfig, UserContextProvider, type WalletHandlerApi, type WalletHandlerConfig, type WalletRequestKind, type WalletRequestStatus, cn, formatAddress, getChainInfo, getNetworkName, initThreadControl, useAomiRuntime, useControl, useCurrentThreadMessages, useCurrentThreadMetadata, useEventContext, useNotification, useNotificationHandler, useThreadContext, useUser, useWalletHandler };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AomiClient, Session, WalletRequest,
|
|
2
|
-
export { AomiChatResponse, AomiClient, AomiClientOptions, AomiCreateThreadResponse, AomiInterruptResponse, AomiMessage, AomiSSEEvent, AomiStateResponse, AomiSystemEvent, AomiSystemResponse, AomiThread, UserState, WalletEip712Payload, WalletRequest, WalletTxPayload, toViemSignTypedDataArgs } from '@aomi-labs/client';
|
|
1
|
+
import { AomiClient, SessionOptions, Session, UserState, WalletRequest, WalletRequestResult, AomiSimulateResponse } from '@aomi-labs/client';
|
|
2
|
+
export { AomiChatResponse, AomiClient, AomiClientOptions, AomiCreateThreadResponse, AomiInterruptResponse, AomiMessage, AomiSSEEvent, AomiStateResponse, AomiSystemEvent, AomiSystemResponse, AomiThread, DISABLED_PROVIDER_STATE, MAX_AUTO_FEE_WEI, UserState, WalletEip712Payload, WalletRequest, WalletRequestResult, WalletTxPayload, aaModeFromExecutionKind, appendFeeCallToPayload, buildFeeAAWalletCall, executeWalletCalls, hydrateTxPayloadFromUserState, normalizeSimulatedFee, parseChainId, toAAWalletCall, toAAWalletCalls, toViemSignTypedDataArgs } from '@aomi-labs/client';
|
|
3
3
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
4
|
import { ReactNode, SetStateAction } from 'react';
|
|
5
5
|
import { ThreadMessageLike } from '@assistant-ui/react';
|
|
@@ -11,6 +11,25 @@ type AomiRuntimeProviderProps = {
|
|
|
11
11
|
};
|
|
12
12
|
declare function AomiRuntimeProvider({ children, backendUrl, }: Readonly<AomiRuntimeProviderProps>): react_jsx_runtime.JSX.Element;
|
|
13
13
|
|
|
14
|
+
declare class SessionManager {
|
|
15
|
+
private readonly clientFactory;
|
|
16
|
+
private sessions;
|
|
17
|
+
constructor(clientFactory: () => AomiClient);
|
|
18
|
+
getOrCreate(threadId: string, opts: Omit<SessionOptions, "sessionId">): Session;
|
|
19
|
+
get(threadId: string): Session | undefined;
|
|
20
|
+
forEach(callback: (session: Session, threadId: string) => void): void;
|
|
21
|
+
close(threadId: string): void;
|
|
22
|
+
closeAll(): void;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
type RuntimeUserStateProviderProps = {
|
|
26
|
+
children: ReactNode;
|
|
27
|
+
sessionManager: SessionManager;
|
|
28
|
+
getUserState: () => UserState;
|
|
29
|
+
onUserStateChange: (callback: (user: UserState) => void) => () => void;
|
|
30
|
+
};
|
|
31
|
+
declare function RuntimeUserStateProvider({ children, sessionManager, getUserState, onUserStateChange, }: RuntimeUserStateProviderProps): react_jsx_runtime.JSX.Element;
|
|
32
|
+
|
|
14
33
|
type ThreadContext = {
|
|
15
34
|
currentThreadId: string;
|
|
16
35
|
setCurrentThreadId: (id: string) => void;
|
|
@@ -121,11 +140,6 @@ declare function NotificationContextProvider({ children, }: NotificationContextP
|
|
|
121
140
|
|
|
122
141
|
type WalletRequestKind = "transaction" | "eip712_sign";
|
|
123
142
|
type WalletRequestStatus = "pending" | "processing";
|
|
124
|
-
type WalletRequestResult = {
|
|
125
|
-
txHash?: string;
|
|
126
|
-
signature?: string;
|
|
127
|
-
amount?: string;
|
|
128
|
-
};
|
|
129
143
|
type WalletHandlerConfig = {
|
|
130
144
|
/** Get the ClientSession for the current thread. */
|
|
131
145
|
getSession: () => Session | undefined;
|
|
@@ -193,12 +207,24 @@ type AomiRuntimeApi = {
|
|
|
193
207
|
clearAllNotifications: () => void;
|
|
194
208
|
/** All queued wallet requests (tx + eip712 signing) */
|
|
195
209
|
pendingWalletRequests: WalletRequest[];
|
|
196
|
-
/** Mark a wallet request as
|
|
210
|
+
/** Mark a wallet request as in-flight — suppresses it from the pending list until acked */
|
|
197
211
|
startWalletRequest: (id: string) => void;
|
|
198
212
|
/** Complete a wallet request after the backend acknowledges the response */
|
|
199
213
|
resolveWalletRequest: (id: string, result: WalletRequestResult) => Promise<void>;
|
|
200
214
|
/** Fail a wallet request after the backend acknowledges the error */
|
|
201
215
|
rejectWalletRequest: (id: string, error?: string) => Promise<void>;
|
|
216
|
+
/** Simulate a batch against the current thread session context. */
|
|
217
|
+
simulateBatchTransactions: (transactions: Array<{
|
|
218
|
+
to: string;
|
|
219
|
+
value?: string;
|
|
220
|
+
data?: string;
|
|
221
|
+
label?: string;
|
|
222
|
+
chain_id?: number;
|
|
223
|
+
chainId?: number;
|
|
224
|
+
}>, options?: {
|
|
225
|
+
from?: string;
|
|
226
|
+
chainId?: number;
|
|
227
|
+
}) => Promise<AomiSimulateResponse["result"]>;
|
|
202
228
|
/** Subscribe to inbound events by type. Returns unsubscribe function. */
|
|
203
229
|
subscribe: (type: string, callback: EventSubscriber) => () => void;
|
|
204
230
|
/** Send a system command to the backend */
|
|
@@ -380,4 +406,4 @@ type ControlContextProviderProps = {
|
|
|
380
406
|
};
|
|
381
407
|
declare function ControlContextProvider({ children, aomiClient, sessionId, publicKey, getThreadMetadata, updateThreadMetadata, }: ControlContextProviderProps): react_jsx_runtime.JSX.Element;
|
|
382
408
|
|
|
383
|
-
export { type AomiRuntimeApi, AomiRuntimeProvider, type AomiRuntimeProviderProps, type ChainInfo, type ControlContextApi, ControlContextProvider, type ControlContextProviderProps, type ControlState, type EventContext, EventContextProvider, type EventContextProviderProps, type EventSubscriber, type InboundEvent, type Notification$1 as Notification, type NotificationApi, NotificationContextProvider, type NotificationContextProviderProps, type NotificationContextApi as NotificationContextValue, type NotificationHandlerConfig, type NotificationType, type SSEStatus, SUPPORTED_CHAINS, type NotificationData as ShowNotificationParams, type StoredProviderKey, type ThreadContext, ThreadContextProvider, type ThreadControlState, type ThreadMetadata, type UserConfig, UserContextProvider, type WalletHandlerApi, type WalletHandlerConfig, type WalletRequestKind, type
|
|
409
|
+
export { type AomiRuntimeApi, AomiRuntimeProvider, type AomiRuntimeProviderProps, type ChainInfo, type ControlContextApi, ControlContextProvider, type ControlContextProviderProps, type ControlState, type EventContext, EventContextProvider, type EventContextProviderProps, type EventSubscriber, type InboundEvent, type Notification$1 as Notification, type NotificationApi, NotificationContextProvider, type NotificationContextProviderProps, type NotificationContextApi as NotificationContextValue, type NotificationHandlerConfig, type NotificationType, RuntimeUserStateProvider, type SSEStatus, SUPPORTED_CHAINS, type NotificationData as ShowNotificationParams, type StoredProviderKey, type ThreadContext, ThreadContextProvider, type ThreadControlState, type ThreadMetadata, type UserConfig, UserContextProvider, type WalletHandlerApi, type WalletHandlerConfig, type WalletRequestKind, type WalletRequestStatus, cn, formatAddress, getChainInfo, getNetworkName, initThreadControl, useAomiRuntime, useControl, useCurrentThreadMessages, useCurrentThreadMetadata, useEventContext, useNotification, useNotificationHandler, useThreadContext, useUser, useWalletHandler };
|
package/dist/index.js
CHANGED
|
@@ -33,7 +33,20 @@ var __objRest = (source, exclude) => {
|
|
|
33
33
|
|
|
34
34
|
// packages/react/src/index.ts
|
|
35
35
|
import { AomiClient as AomiClient2 } from "@aomi-labs/client";
|
|
36
|
-
import {
|
|
36
|
+
import {
|
|
37
|
+
toViemSignTypedDataArgs,
|
|
38
|
+
hydrateTxPayloadFromUserState,
|
|
39
|
+
toAAWalletCalls,
|
|
40
|
+
toAAWalletCall,
|
|
41
|
+
appendFeeCallToPayload,
|
|
42
|
+
buildFeeAAWalletCall,
|
|
43
|
+
normalizeSimulatedFee,
|
|
44
|
+
MAX_AUTO_FEE_WEI,
|
|
45
|
+
executeWalletCalls,
|
|
46
|
+
DISABLED_PROVIDER_STATE,
|
|
47
|
+
parseChainId,
|
|
48
|
+
aaModeFromExecutionKind
|
|
49
|
+
} from "@aomi-labs/client";
|
|
37
50
|
|
|
38
51
|
// packages/react/src/runtime/aomi-runtime.tsx
|
|
39
52
|
import { useMemo as useMemo3 } from "react";
|
|
@@ -911,30 +924,46 @@ function UserContextProvider({ children }) {
|
|
|
911
924
|
const StateChangeCallbacks = useRef4(
|
|
912
925
|
/* @__PURE__ */ new Set()
|
|
913
926
|
);
|
|
927
|
+
const notifyStateChange = useCallback4((next) => {
|
|
928
|
+
queueMicrotask(() => {
|
|
929
|
+
StateChangeCallbacks.current.forEach((callback) => {
|
|
930
|
+
callback(next);
|
|
931
|
+
});
|
|
932
|
+
});
|
|
933
|
+
}, []);
|
|
934
|
+
const pruneUndefined = useCallback4((state) => {
|
|
935
|
+
return Object.fromEntries(
|
|
936
|
+
Object.entries(state).filter(([, value]) => value !== void 0)
|
|
937
|
+
);
|
|
938
|
+
}, []);
|
|
914
939
|
const setUser = useCallback4((data) => {
|
|
915
940
|
setUserState((prev) => {
|
|
916
941
|
var _a, _b, _c;
|
|
917
|
-
const normalizedData = (_a = UserState.normalize(data)) != null ? _a : {};
|
|
918
|
-
const
|
|
942
|
+
const normalizedData = pruneUndefined((_a = UserState.normalize(data)) != null ? _a : {});
|
|
943
|
+
const nextPartial = __spreadValues({}, normalizedData);
|
|
944
|
+
if (nextPartial.is_connected === true && nextPartial.chain_id === void 0) {
|
|
945
|
+
if (prev.chain_id !== void 0) {
|
|
946
|
+
nextPartial.chain_id = prev.chain_id;
|
|
947
|
+
} else {
|
|
948
|
+
delete nextPartial.is_connected;
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
const next = nextPartial.is_connected === false ? __spreadProps(__spreadValues({}, (_b = UserState.normalize(__spreadValues(__spreadValues({}, prev), nextPartial))) != null ? _b : prev), {
|
|
919
952
|
address: void 0,
|
|
920
953
|
chain_id: void 0,
|
|
921
954
|
ens_name: void 0
|
|
922
|
-
}) : (_c = UserState.normalize(__spreadValues(__spreadValues({}, prev),
|
|
923
|
-
|
|
924
|
-
callback(next);
|
|
925
|
-
});
|
|
955
|
+
}) : (_c = UserState.normalize(__spreadValues(__spreadValues({}, prev), nextPartial))) != null ? _c : prev;
|
|
956
|
+
notifyStateChange(next);
|
|
926
957
|
return next;
|
|
927
958
|
});
|
|
928
|
-
}, []);
|
|
959
|
+
}, [notifyStateChange, pruneUndefined]);
|
|
929
960
|
const addExtValue = useCallback4((key, value) => {
|
|
930
961
|
setUserState((prev) => {
|
|
931
962
|
const next = UserState.withExt(prev, key, value);
|
|
932
|
-
|
|
933
|
-
callback(next);
|
|
934
|
-
});
|
|
963
|
+
notifyStateChange(next);
|
|
935
964
|
return next;
|
|
936
965
|
});
|
|
937
|
-
}, []);
|
|
966
|
+
}, [notifyStateChange]);
|
|
938
967
|
const removeExtValue = useCallback4((key) => {
|
|
939
968
|
setUserState((prev) => {
|
|
940
969
|
const ext = prev.ext;
|
|
@@ -946,12 +975,10 @@ function UserContextProvider({ children }) {
|
|
|
946
975
|
const next = __spreadProps(__spreadValues({}, prev), {
|
|
947
976
|
ext: Object.keys(nextExt).length > 0 ? nextExt : void 0
|
|
948
977
|
});
|
|
949
|
-
|
|
950
|
-
callback(next);
|
|
951
|
-
});
|
|
978
|
+
notifyStateChange(next);
|
|
952
979
|
return next;
|
|
953
980
|
});
|
|
954
|
-
}, []);
|
|
981
|
+
}, [notifyStateChange]);
|
|
955
982
|
const getUserState = useCallback4(() => userRef.current, []);
|
|
956
983
|
const onUserStateChange = useCallback4(
|
|
957
984
|
(callback) => {
|
|
@@ -979,7 +1006,7 @@ function UserContextProvider({ children }) {
|
|
|
979
1006
|
}
|
|
980
1007
|
|
|
981
1008
|
// packages/react/src/runtime/core.tsx
|
|
982
|
-
import { useCallback as useCallback7, useEffect as
|
|
1009
|
+
import { useCallback as useCallback7, useEffect as useEffect4, useMemo as useMemo2, useRef as useRef8 } from "react";
|
|
983
1010
|
import {
|
|
984
1011
|
AssistantRuntimeProvider,
|
|
985
1012
|
useExternalStoreRuntime
|
|
@@ -988,6 +1015,7 @@ import { UserState as UserState3 } from "@aomi-labs/client";
|
|
|
988
1015
|
|
|
989
1016
|
// packages/react/src/runtime/orchestrator.ts
|
|
990
1017
|
import { useCallback as useCallback5, useEffect as useEffect2, useRef as useRef5, useState as useState4 } from "react";
|
|
1018
|
+
import { CLIENT_TYPE_WEB_UI } from "@aomi-labs/client";
|
|
991
1019
|
|
|
992
1020
|
// packages/react/src/runtime/session-manager.ts
|
|
993
1021
|
import { Session as ClientSession } from "@aomi-labs/client";
|
|
@@ -1008,6 +1036,11 @@ var SessionManager = class {
|
|
|
1008
1036
|
get(threadId) {
|
|
1009
1037
|
return this.sessions.get(threadId);
|
|
1010
1038
|
}
|
|
1039
|
+
forEach(callback) {
|
|
1040
|
+
for (const [threadId, session] of this.sessions) {
|
|
1041
|
+
callback(session, threadId);
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1011
1044
|
close(threadId) {
|
|
1012
1045
|
const session = this.sessions.get(threadId);
|
|
1013
1046
|
if (session) {
|
|
@@ -1164,6 +1197,8 @@ function useRuntimeOrchestrator(aomiClient, options) {
|
|
|
1164
1197
|
publicKey: nextPublicKey,
|
|
1165
1198
|
apiKey: nextApiKey,
|
|
1166
1199
|
clientId: nextClientId,
|
|
1200
|
+
clientType: CLIENT_TYPE_WEB_UI,
|
|
1201
|
+
syncPendingTxRequestsFromUserState: false,
|
|
1167
1202
|
userState: nextUserState
|
|
1168
1203
|
});
|
|
1169
1204
|
const cleanups = [];
|
|
@@ -1224,15 +1259,13 @@ function useRuntimeOrchestrator(aomiClient, options) {
|
|
|
1224
1259
|
);
|
|
1225
1260
|
const ensureInitialState = useCallback5(
|
|
1226
1261
|
async (threadId) => {
|
|
1227
|
-
var _a
|
|
1262
|
+
var _a;
|
|
1228
1263
|
if (pendingFetches.current.has(threadId)) return;
|
|
1229
1264
|
pendingFetches.current.add(threadId);
|
|
1230
1265
|
try {
|
|
1231
1266
|
const session = getSession(threadId);
|
|
1232
|
-
const userState = (_a = options.getUserState) == null ? void 0 : _a.call(options);
|
|
1233
|
-
if (userState) session.resolveUserState(userState);
|
|
1234
1267
|
await session.fetchCurrentState();
|
|
1235
|
-
(
|
|
1268
|
+
(_a = options.onPendingRequestsChange) == null ? void 0 : _a.call(options, session.getPendingRequests());
|
|
1236
1269
|
if (threadContextRef.current.currentThreadId === threadId) {
|
|
1237
1270
|
setIsRunning(session.getIsProcessing());
|
|
1238
1271
|
}
|
|
@@ -1249,10 +1282,8 @@ function useRuntimeOrchestrator(aomiClient, options) {
|
|
|
1249
1282
|
);
|
|
1250
1283
|
const sendMessage = useCallback5(
|
|
1251
1284
|
async (text, threadId) => {
|
|
1252
|
-
var _a
|
|
1285
|
+
var _a;
|
|
1253
1286
|
const session = getSession(threadId);
|
|
1254
|
-
const userState = (_a = options.getUserState) == null ? void 0 : _a.call(options);
|
|
1255
|
-
if (userState) session.resolveUserState(userState);
|
|
1256
1287
|
const existingMessages = threadContextRef.current.getThreadMessages(threadId);
|
|
1257
1288
|
const userMessage = {
|
|
1258
1289
|
role: "user",
|
|
@@ -1267,7 +1298,7 @@ function useRuntimeOrchestrator(aomiClient, options) {
|
|
|
1267
1298
|
lastActiveAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1268
1299
|
});
|
|
1269
1300
|
await session.sendAsync(text);
|
|
1270
|
-
(
|
|
1301
|
+
(_a = options.onPendingRequestsChange) == null ? void 0 : _a.call(options, session.getPendingRequests());
|
|
1271
1302
|
},
|
|
1272
1303
|
[getSession]
|
|
1273
1304
|
);
|
|
@@ -1539,8 +1570,41 @@ function useWalletHandler({
|
|
|
1539
1570
|
};
|
|
1540
1571
|
}
|
|
1541
1572
|
|
|
1573
|
+
// packages/react/src/runtime/user-state-provider.tsx
|
|
1574
|
+
import { useEffect as useEffect3, useRef as useRef7 } from "react";
|
|
1575
|
+
import { Fragment, jsx as jsx6 } from "react/jsx-runtime";
|
|
1576
|
+
function stableStateString(state) {
|
|
1577
|
+
return JSON.stringify(state != null ? state : {});
|
|
1578
|
+
}
|
|
1579
|
+
function RuntimeUserStateProvider({
|
|
1580
|
+
children,
|
|
1581
|
+
sessionManager,
|
|
1582
|
+
getUserState,
|
|
1583
|
+
onUserStateChange
|
|
1584
|
+
}) {
|
|
1585
|
+
const lastSerializedStateRef = useRef7("");
|
|
1586
|
+
useEffect3(() => {
|
|
1587
|
+
const applyToSessions = (next) => {
|
|
1588
|
+
const serialized = stableStateString(next);
|
|
1589
|
+
if (serialized === lastSerializedStateRef.current) {
|
|
1590
|
+
return;
|
|
1591
|
+
}
|
|
1592
|
+
lastSerializedStateRef.current = serialized;
|
|
1593
|
+
sessionManager.forEach((session) => {
|
|
1594
|
+
session.resolveUserState(next);
|
|
1595
|
+
});
|
|
1596
|
+
};
|
|
1597
|
+
applyToSessions(getUserState());
|
|
1598
|
+
const unsubscribe = onUserStateChange((next) => {
|
|
1599
|
+
applyToSessions(next);
|
|
1600
|
+
});
|
|
1601
|
+
return unsubscribe;
|
|
1602
|
+
}, [getUserState, onUserStateChange, sessionManager]);
|
|
1603
|
+
return /* @__PURE__ */ jsx6(Fragment, { children });
|
|
1604
|
+
}
|
|
1605
|
+
|
|
1542
1606
|
// packages/react/src/runtime/core.tsx
|
|
1543
|
-
import { jsx as
|
|
1607
|
+
import { jsx as jsx7 } from "react/jsx-runtime";
|
|
1544
1608
|
function AomiRuntimeCore({
|
|
1545
1609
|
children,
|
|
1546
1610
|
aomiClient
|
|
@@ -1550,7 +1614,7 @@ function AomiRuntimeCore({
|
|
|
1550
1614
|
const notificationContext = useNotification();
|
|
1551
1615
|
const { user, onUserStateChange, getUserState } = useUser();
|
|
1552
1616
|
const { getControlState, getCurrentThreadApp } = useControl();
|
|
1553
|
-
const sessionManagerRef =
|
|
1617
|
+
const sessionManagerRef = useRef8(null);
|
|
1554
1618
|
const walletHandler = useWalletHandler({
|
|
1555
1619
|
getSession: () => {
|
|
1556
1620
|
var _a;
|
|
@@ -1591,8 +1655,8 @@ function AomiRuntimeCore({
|
|
|
1591
1655
|
},
|
|
1592
1656
|
[getUserState]
|
|
1593
1657
|
);
|
|
1594
|
-
const lastWalletStateRef =
|
|
1595
|
-
|
|
1658
|
+
const lastWalletStateRef = useRef8(walletSnapshot(getUserState()));
|
|
1659
|
+
useEffect4(() => {
|
|
1596
1660
|
lastWalletStateRef.current = walletSnapshot(getUserState());
|
|
1597
1661
|
const unsubscribe = onUserStateChange(async (newUser) => {
|
|
1598
1662
|
const nextWalletState = walletSnapshot(newUser);
|
|
@@ -1616,10 +1680,10 @@ function AomiRuntimeCore({
|
|
|
1616
1680
|
getUserState,
|
|
1617
1681
|
walletSnapshot
|
|
1618
1682
|
]);
|
|
1619
|
-
const threadContextRef =
|
|
1683
|
+
const threadContextRef = useRef8(threadContext);
|
|
1620
1684
|
threadContextRef.current = threadContext;
|
|
1621
|
-
const remoteThreadIdsRef =
|
|
1622
|
-
const warmedThreadIdsRef =
|
|
1685
|
+
const remoteThreadIdsRef = useRef8(/* @__PURE__ */ new Set());
|
|
1686
|
+
const warmedThreadIdsRef = useRef8(/* @__PURE__ */ new Set());
|
|
1623
1687
|
const warmThread = useCallback7(
|
|
1624
1688
|
async (threadId) => {
|
|
1625
1689
|
if (!remoteThreadIdsRef.current.has(threadId) || warmedThreadIdsRef.current.has(threadId)) {
|
|
@@ -1634,7 +1698,7 @@ function AomiRuntimeCore({
|
|
|
1634
1698
|
},
|
|
1635
1699
|
[aomiClientRef, getUserState]
|
|
1636
1700
|
);
|
|
1637
|
-
|
|
1701
|
+
useEffect4(() => {
|
|
1638
1702
|
const unsubscribe = eventContext.subscribe(
|
|
1639
1703
|
"user_state_request",
|
|
1640
1704
|
() => {
|
|
@@ -1649,7 +1713,7 @@ function AomiRuntimeCore({
|
|
|
1649
1713
|
);
|
|
1650
1714
|
return unsubscribe;
|
|
1651
1715
|
}, [eventContext, threadContext.currentThreadId, getSession, getUserState]);
|
|
1652
|
-
|
|
1716
|
+
useEffect4(() => {
|
|
1653
1717
|
const threadId = threadContext.currentThreadId;
|
|
1654
1718
|
let cancelled = false;
|
|
1655
1719
|
void (async () => {
|
|
@@ -1662,7 +1726,7 @@ function AomiRuntimeCore({
|
|
|
1662
1726
|
cancelled = true;
|
|
1663
1727
|
};
|
|
1664
1728
|
}, [ensureInitialState, threadContext.currentThreadId, warmThread]);
|
|
1665
|
-
|
|
1729
|
+
useEffect4(() => {
|
|
1666
1730
|
const threadId = threadContext.currentThreadId;
|
|
1667
1731
|
const currentMeta = threadContext.getThreadMetadata(threadId);
|
|
1668
1732
|
if (currentMeta && currentMeta.control.isProcessing !== isRunning) {
|
|
@@ -1676,7 +1740,7 @@ function AomiRuntimeCore({
|
|
|
1676
1740
|
const currentMessages = threadContext.getThreadMessages(
|
|
1677
1741
|
threadContext.currentThreadId
|
|
1678
1742
|
);
|
|
1679
|
-
|
|
1743
|
+
useEffect4(() => {
|
|
1680
1744
|
const userAddress = UserState3.isConnected(user) ? UserState3.address(user) : void 0;
|
|
1681
1745
|
if (!userAddress) {
|
|
1682
1746
|
remoteThreadIdsRef.current.clear();
|
|
@@ -1745,7 +1809,7 @@ function AomiRuntimeCore({
|
|
|
1745
1809
|
threadContext.allThreadsMetadata
|
|
1746
1810
|
]
|
|
1747
1811
|
);
|
|
1748
|
-
|
|
1812
|
+
useEffect4(() => {
|
|
1749
1813
|
const showToolNotification = (eventType) => (event) => {
|
|
1750
1814
|
const payload = event.payload;
|
|
1751
1815
|
const toolName = typeof (payload == null ? void 0 : payload.tool_name) === "string" ? payload.tool_name : void 0;
|
|
@@ -1770,7 +1834,7 @@ function AomiRuntimeCore({
|
|
|
1770
1834
|
unsubscribeComplete();
|
|
1771
1835
|
};
|
|
1772
1836
|
}, [eventContext, notificationContext]);
|
|
1773
|
-
|
|
1837
|
+
useEffect4(() => {
|
|
1774
1838
|
const unsubscribe = eventContext.subscribe("system_notice", (_event) => {
|
|
1775
1839
|
});
|
|
1776
1840
|
return unsubscribe;
|
|
@@ -1793,7 +1857,7 @@ function AomiRuntimeCore({
|
|
|
1793
1857
|
convertMessage: (msg) => msg,
|
|
1794
1858
|
adapters: { threadList: threadListAdapter }
|
|
1795
1859
|
});
|
|
1796
|
-
|
|
1860
|
+
useEffect4(() => {
|
|
1797
1861
|
return () => {
|
|
1798
1862
|
sessionManager.closeAll();
|
|
1799
1863
|
};
|
|
@@ -1848,6 +1912,22 @@ function AomiRuntimeCore({
|
|
|
1848
1912
|
},
|
|
1849
1913
|
[threadContext.allThreadsMetadata, threadListAdapter]
|
|
1850
1914
|
);
|
|
1915
|
+
const simulateBatchTransactions = useCallback7(
|
|
1916
|
+
async (transactions, options) => {
|
|
1917
|
+
var _a, _b;
|
|
1918
|
+
const session = (_b = (_a = sessionManagerRef.current) == null ? void 0 : _a.get(threadContext.currentThreadId)) != null ? _b : getSession(threadContext.currentThreadId);
|
|
1919
|
+
if (!session) {
|
|
1920
|
+
throw new Error("runtime_session_unavailable");
|
|
1921
|
+
}
|
|
1922
|
+
const response = await session.client.simulateBatch(
|
|
1923
|
+
session.sessionId,
|
|
1924
|
+
transactions,
|
|
1925
|
+
options
|
|
1926
|
+
);
|
|
1927
|
+
return response.result;
|
|
1928
|
+
},
|
|
1929
|
+
[getSession, threadContext.currentThreadId]
|
|
1930
|
+
);
|
|
1851
1931
|
const aomiRuntimeApi = useMemo2(
|
|
1852
1932
|
() => ({
|
|
1853
1933
|
// User API
|
|
@@ -1882,6 +1962,7 @@ function AomiRuntimeCore({
|
|
|
1882
1962
|
startWalletRequest: walletHandler.startRequest,
|
|
1883
1963
|
resolveWalletRequest: walletHandler.resolveRequest,
|
|
1884
1964
|
rejectWalletRequest: walletHandler.rejectRequest,
|
|
1965
|
+
simulateBatchTransactions,
|
|
1885
1966
|
// Event API
|
|
1886
1967
|
subscribe: eventContext.subscribe,
|
|
1887
1968
|
sendSystemCommand: eventContext.sendOutboundSystem,
|
|
@@ -1904,20 +1985,29 @@ function AomiRuntimeCore({
|
|
|
1904
1985
|
cancelGeneration,
|
|
1905
1986
|
notificationContext,
|
|
1906
1987
|
walletHandler,
|
|
1988
|
+
simulateBatchTransactions,
|
|
1907
1989
|
eventContext
|
|
1908
1990
|
]
|
|
1909
1991
|
);
|
|
1910
|
-
return /* @__PURE__ */
|
|
1992
|
+
return /* @__PURE__ */ jsx7(AomiRuntimeApiProvider, { value: aomiRuntimeApi, children: /* @__PURE__ */ jsx7(
|
|
1993
|
+
RuntimeUserStateProvider,
|
|
1994
|
+
{
|
|
1995
|
+
sessionManager,
|
|
1996
|
+
getUserState: userContext.getUserState,
|
|
1997
|
+
onUserStateChange: userContext.onUserStateChange,
|
|
1998
|
+
children: /* @__PURE__ */ jsx7(AssistantRuntimeProvider, { runtime, children })
|
|
1999
|
+
}
|
|
2000
|
+
) });
|
|
1911
2001
|
}
|
|
1912
2002
|
|
|
1913
2003
|
// packages/react/src/runtime/aomi-runtime.tsx
|
|
1914
|
-
import { jsx as
|
|
2004
|
+
import { jsx as jsx8 } from "react/jsx-runtime";
|
|
1915
2005
|
function AomiRuntimeProvider({
|
|
1916
2006
|
children,
|
|
1917
2007
|
backendUrl = "http://localhost:8080"
|
|
1918
2008
|
}) {
|
|
1919
2009
|
const aomiClient = useMemo3(() => new AomiClient({ baseUrl: backendUrl }), [backendUrl]);
|
|
1920
|
-
return /* @__PURE__ */
|
|
2010
|
+
return /* @__PURE__ */ jsx8(ThreadContextProvider, { children: /* @__PURE__ */ jsx8(NotificationContextProvider, { children: /* @__PURE__ */ jsx8(UserContextProvider, { children: /* @__PURE__ */ jsx8(AomiRuntimeInner, { aomiClient, children }) }) }) });
|
|
1921
2011
|
}
|
|
1922
2012
|
function AomiRuntimeInner({
|
|
1923
2013
|
children,
|
|
@@ -1926,7 +2016,7 @@ function AomiRuntimeInner({
|
|
|
1926
2016
|
var _a;
|
|
1927
2017
|
const threadContext = useThreadContext();
|
|
1928
2018
|
const { user } = useUser();
|
|
1929
|
-
return /* @__PURE__ */
|
|
2019
|
+
return /* @__PURE__ */ jsx8(
|
|
1930
2020
|
ControlContextProvider,
|
|
1931
2021
|
{
|
|
1932
2022
|
aomiClient,
|
|
@@ -1934,12 +2024,12 @@ function AomiRuntimeInner({
|
|
|
1934
2024
|
publicKey: UserState4.isConnected(user) ? (_a = UserState4.address(user)) != null ? _a : void 0 : void 0,
|
|
1935
2025
|
getThreadMetadata: threadContext.getThreadMetadata,
|
|
1936
2026
|
updateThreadMetadata: threadContext.updateThreadMetadata,
|
|
1937
|
-
children: /* @__PURE__ */
|
|
2027
|
+
children: /* @__PURE__ */ jsx8(
|
|
1938
2028
|
EventContextProvider,
|
|
1939
2029
|
{
|
|
1940
2030
|
aomiClient,
|
|
1941
2031
|
sessionId: threadContext.currentThreadId,
|
|
1942
|
-
children: /* @__PURE__ */
|
|
2032
|
+
children: /* @__PURE__ */ jsx8(AomiRuntimeCore, { aomiClient, children })
|
|
1943
2033
|
}
|
|
1944
2034
|
)
|
|
1945
2035
|
}
|
|
@@ -1947,7 +2037,7 @@ function AomiRuntimeInner({
|
|
|
1947
2037
|
}
|
|
1948
2038
|
|
|
1949
2039
|
// packages/react/src/handlers/notification-handler.ts
|
|
1950
|
-
import { useCallback as useCallback8, useEffect as
|
|
2040
|
+
import { useCallback as useCallback8, useEffect as useEffect5, useState as useState6 } from "react";
|
|
1951
2041
|
var notificationIdCounter2 = 0;
|
|
1952
2042
|
function generateNotificationId() {
|
|
1953
2043
|
return `notif-${Date.now()}-${++notificationIdCounter2}`;
|
|
@@ -1957,7 +2047,7 @@ function useNotificationHandler({
|
|
|
1957
2047
|
} = {}) {
|
|
1958
2048
|
const { subscribe } = useEventContext();
|
|
1959
2049
|
const [notifications, setNotifications] = useState6([]);
|
|
1960
|
-
|
|
2050
|
+
useEffect5(() => {
|
|
1961
2051
|
const unsubscribe = subscribe("notification", (event) => {
|
|
1962
2052
|
var _a, _b;
|
|
1963
2053
|
const payload = event.payload;
|
|
@@ -1991,16 +2081,28 @@ export {
|
|
|
1991
2081
|
AomiClient2 as AomiClient,
|
|
1992
2082
|
AomiRuntimeProvider,
|
|
1993
2083
|
ControlContextProvider,
|
|
2084
|
+
DISABLED_PROVIDER_STATE,
|
|
1994
2085
|
EventContextProvider,
|
|
2086
|
+
MAX_AUTO_FEE_WEI,
|
|
1995
2087
|
NotificationContextProvider,
|
|
2088
|
+
RuntimeUserStateProvider,
|
|
1996
2089
|
SUPPORTED_CHAINS,
|
|
1997
2090
|
ThreadContextProvider,
|
|
1998
2091
|
UserContextProvider,
|
|
2092
|
+
aaModeFromExecutionKind,
|
|
2093
|
+
appendFeeCallToPayload,
|
|
2094
|
+
buildFeeAAWalletCall,
|
|
1999
2095
|
cn,
|
|
2096
|
+
executeWalletCalls,
|
|
2000
2097
|
formatAddress,
|
|
2001
2098
|
getChainInfo,
|
|
2002
2099
|
getNetworkName,
|
|
2100
|
+
hydrateTxPayloadFromUserState,
|
|
2003
2101
|
initThreadControl,
|
|
2102
|
+
normalizeSimulatedFee,
|
|
2103
|
+
parseChainId,
|
|
2104
|
+
toAAWalletCall,
|
|
2105
|
+
toAAWalletCalls,
|
|
2004
2106
|
toViemSignTypedDataArgs,
|
|
2005
2107
|
useAomiRuntime,
|
|
2006
2108
|
useControl,
|