@aomi-labs/react 0.3.11 → 0.3.13
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 +171 -82
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +23 -9
- package/dist/index.d.ts +23 -9
- package/dist/index.js +143 -53
- 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 } from '@aomi-labs/client';
|
|
2
|
+
export { AomiChatResponse, AomiClient, AomiClientOptions, AomiCreateThreadResponse, AomiInterruptResponse, AomiMessage, AomiSSEEvent, AomiStateResponse, AomiSystemEvent, AomiSystemResponse, AomiThread, DISABLED_PROVIDER_STATE, UserState, WalletEip712Payload, WalletRequest, WalletRequestResult, WalletTxPayload, aaModeFromExecutionKind, executeWalletCalls, hydrateTxPayloadFromUserState, 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,7 +207,7 @@ 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>;
|
|
@@ -380,4 +394,4 @@ type ControlContextProviderProps = {
|
|
|
380
394
|
};
|
|
381
395
|
declare function ControlContextProvider({ children, aomiClient, sessionId, publicKey, getThreadMetadata, updateThreadMetadata, }: ControlContextProviderProps): react_jsx_runtime.JSX.Element;
|
|
382
396
|
|
|
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
|
|
397
|
+
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 } from '@aomi-labs/client';
|
|
2
|
+
export { AomiChatResponse, AomiClient, AomiClientOptions, AomiCreateThreadResponse, AomiInterruptResponse, AomiMessage, AomiSSEEvent, AomiStateResponse, AomiSystemEvent, AomiSystemResponse, AomiThread, DISABLED_PROVIDER_STATE, UserState, WalletEip712Payload, WalletRequest, WalletRequestResult, WalletTxPayload, aaModeFromExecutionKind, executeWalletCalls, hydrateTxPayloadFromUserState, 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,7 +207,7 @@ 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>;
|
|
@@ -380,4 +394,4 @@ type ControlContextProviderProps = {
|
|
|
380
394
|
};
|
|
381
395
|
declare function ControlContextProvider({ children, aomiClient, sessionId, publicKey, getThreadMetadata, updateThreadMetadata, }: ControlContextProviderProps): react_jsx_runtime.JSX.Element;
|
|
382
396
|
|
|
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
|
|
397
|
+
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,16 @@ 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
|
+
executeWalletCalls,
|
|
42
|
+
DISABLED_PROVIDER_STATE,
|
|
43
|
+
parseChainId,
|
|
44
|
+
aaModeFromExecutionKind
|
|
45
|
+
} from "@aomi-labs/client";
|
|
37
46
|
|
|
38
47
|
// packages/react/src/runtime/aomi-runtime.tsx
|
|
39
48
|
import { useMemo as useMemo3 } from "react";
|
|
@@ -911,30 +920,46 @@ function UserContextProvider({ children }) {
|
|
|
911
920
|
const StateChangeCallbacks = useRef4(
|
|
912
921
|
/* @__PURE__ */ new Set()
|
|
913
922
|
);
|
|
923
|
+
const notifyStateChange = useCallback4((next) => {
|
|
924
|
+
queueMicrotask(() => {
|
|
925
|
+
StateChangeCallbacks.current.forEach((callback) => {
|
|
926
|
+
callback(next);
|
|
927
|
+
});
|
|
928
|
+
});
|
|
929
|
+
}, []);
|
|
930
|
+
const pruneUndefined = useCallback4((state) => {
|
|
931
|
+
return Object.fromEntries(
|
|
932
|
+
Object.entries(state).filter(([, value]) => value !== void 0)
|
|
933
|
+
);
|
|
934
|
+
}, []);
|
|
914
935
|
const setUser = useCallback4((data) => {
|
|
915
936
|
setUserState((prev) => {
|
|
916
937
|
var _a, _b, _c;
|
|
917
|
-
const normalizedData = (_a = UserState.normalize(data)) != null ? _a : {};
|
|
918
|
-
const
|
|
938
|
+
const normalizedData = pruneUndefined((_a = UserState.normalize(data)) != null ? _a : {});
|
|
939
|
+
const nextPartial = __spreadValues({}, normalizedData);
|
|
940
|
+
if (nextPartial.is_connected === true && nextPartial.chain_id === void 0) {
|
|
941
|
+
if (prev.chain_id !== void 0) {
|
|
942
|
+
nextPartial.chain_id = prev.chain_id;
|
|
943
|
+
} else {
|
|
944
|
+
delete nextPartial.is_connected;
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
const next = nextPartial.is_connected === false ? __spreadProps(__spreadValues({}, (_b = UserState.normalize(__spreadValues(__spreadValues({}, prev), nextPartial))) != null ? _b : prev), {
|
|
919
948
|
address: void 0,
|
|
920
949
|
chain_id: void 0,
|
|
921
950
|
ens_name: void 0
|
|
922
|
-
}) : (_c = UserState.normalize(__spreadValues(__spreadValues({}, prev),
|
|
923
|
-
|
|
924
|
-
callback(next);
|
|
925
|
-
});
|
|
951
|
+
}) : (_c = UserState.normalize(__spreadValues(__spreadValues({}, prev), nextPartial))) != null ? _c : prev;
|
|
952
|
+
notifyStateChange(next);
|
|
926
953
|
return next;
|
|
927
954
|
});
|
|
928
|
-
}, []);
|
|
955
|
+
}, [notifyStateChange, pruneUndefined]);
|
|
929
956
|
const addExtValue = useCallback4((key, value) => {
|
|
930
957
|
setUserState((prev) => {
|
|
931
958
|
const next = UserState.withExt(prev, key, value);
|
|
932
|
-
|
|
933
|
-
callback(next);
|
|
934
|
-
});
|
|
959
|
+
notifyStateChange(next);
|
|
935
960
|
return next;
|
|
936
961
|
});
|
|
937
|
-
}, []);
|
|
962
|
+
}, [notifyStateChange]);
|
|
938
963
|
const removeExtValue = useCallback4((key) => {
|
|
939
964
|
setUserState((prev) => {
|
|
940
965
|
const ext = prev.ext;
|
|
@@ -946,12 +971,10 @@ function UserContextProvider({ children }) {
|
|
|
946
971
|
const next = __spreadProps(__spreadValues({}, prev), {
|
|
947
972
|
ext: Object.keys(nextExt).length > 0 ? nextExt : void 0
|
|
948
973
|
});
|
|
949
|
-
|
|
950
|
-
callback(next);
|
|
951
|
-
});
|
|
974
|
+
notifyStateChange(next);
|
|
952
975
|
return next;
|
|
953
976
|
});
|
|
954
|
-
}, []);
|
|
977
|
+
}, [notifyStateChange]);
|
|
955
978
|
const getUserState = useCallback4(() => userRef.current, []);
|
|
956
979
|
const onUserStateChange = useCallback4(
|
|
957
980
|
(callback) => {
|
|
@@ -979,7 +1002,7 @@ function UserContextProvider({ children }) {
|
|
|
979
1002
|
}
|
|
980
1003
|
|
|
981
1004
|
// packages/react/src/runtime/core.tsx
|
|
982
|
-
import { useCallback as useCallback7, useEffect as
|
|
1005
|
+
import { useCallback as useCallback7, useEffect as useEffect4, useMemo as useMemo2, useRef as useRef8 } from "react";
|
|
983
1006
|
import {
|
|
984
1007
|
AssistantRuntimeProvider,
|
|
985
1008
|
useExternalStoreRuntime
|
|
@@ -988,6 +1011,7 @@ import { UserState as UserState3 } from "@aomi-labs/client";
|
|
|
988
1011
|
|
|
989
1012
|
// packages/react/src/runtime/orchestrator.ts
|
|
990
1013
|
import { useCallback as useCallback5, useEffect as useEffect2, useRef as useRef5, useState as useState4 } from "react";
|
|
1014
|
+
import { CLIENT_TYPE_WEB_UI } from "@aomi-labs/client";
|
|
991
1015
|
|
|
992
1016
|
// packages/react/src/runtime/session-manager.ts
|
|
993
1017
|
import { Session as ClientSession } from "@aomi-labs/client";
|
|
@@ -1008,6 +1032,11 @@ var SessionManager = class {
|
|
|
1008
1032
|
get(threadId) {
|
|
1009
1033
|
return this.sessions.get(threadId);
|
|
1010
1034
|
}
|
|
1035
|
+
forEach(callback) {
|
|
1036
|
+
for (const [threadId, session] of this.sessions) {
|
|
1037
|
+
callback(session, threadId);
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1011
1040
|
close(threadId) {
|
|
1012
1041
|
const session = this.sessions.get(threadId);
|
|
1013
1042
|
if (session) {
|
|
@@ -1143,14 +1172,30 @@ function useRuntimeOrchestrator(aomiClient, options) {
|
|
|
1143
1172
|
(threadId) => {
|
|
1144
1173
|
var _a, _b, _c, _d, _e;
|
|
1145
1174
|
const manager = sessionManagerRef.current;
|
|
1175
|
+
const nextApp = options.getApp();
|
|
1176
|
+
const nextPublicKey = (_a = options.getPublicKey) == null ? void 0 : _a.call(options);
|
|
1177
|
+
const nextApiKey = (_c = (_b = options.getApiKey) == null ? void 0 : _b.call(options)) != null ? _c : void 0;
|
|
1178
|
+
const nextClientId = (_d = options.getClientId) == null ? void 0 : _d.call(options);
|
|
1179
|
+
const nextUserState = (_e = options.getUserState) == null ? void 0 : _e.call(options);
|
|
1146
1180
|
const existing = manager.get(threadId);
|
|
1147
|
-
if (existing)
|
|
1181
|
+
if (existing) {
|
|
1182
|
+
existing.syncRuntimeOptions({
|
|
1183
|
+
app: nextApp,
|
|
1184
|
+
publicKey: nextPublicKey,
|
|
1185
|
+
apiKey: nextApiKey,
|
|
1186
|
+
clientId: nextClientId,
|
|
1187
|
+
userState: nextUserState
|
|
1188
|
+
});
|
|
1189
|
+
return existing;
|
|
1190
|
+
}
|
|
1148
1191
|
const session = manager.getOrCreate(threadId, {
|
|
1149
|
-
app:
|
|
1150
|
-
publicKey:
|
|
1151
|
-
apiKey:
|
|
1152
|
-
clientId:
|
|
1153
|
-
|
|
1192
|
+
app: nextApp,
|
|
1193
|
+
publicKey: nextPublicKey,
|
|
1194
|
+
apiKey: nextApiKey,
|
|
1195
|
+
clientId: nextClientId,
|
|
1196
|
+
clientType: CLIENT_TYPE_WEB_UI,
|
|
1197
|
+
syncPendingTxRequestsFromUserState: false,
|
|
1198
|
+
userState: nextUserState
|
|
1154
1199
|
});
|
|
1155
1200
|
const cleanups = [];
|
|
1156
1201
|
cleanups.push(
|
|
@@ -1210,15 +1255,13 @@ function useRuntimeOrchestrator(aomiClient, options) {
|
|
|
1210
1255
|
);
|
|
1211
1256
|
const ensureInitialState = useCallback5(
|
|
1212
1257
|
async (threadId) => {
|
|
1213
|
-
var _a
|
|
1258
|
+
var _a;
|
|
1214
1259
|
if (pendingFetches.current.has(threadId)) return;
|
|
1215
1260
|
pendingFetches.current.add(threadId);
|
|
1216
1261
|
try {
|
|
1217
1262
|
const session = getSession(threadId);
|
|
1218
|
-
const userState = (_a = options.getUserState) == null ? void 0 : _a.call(options);
|
|
1219
|
-
if (userState) session.resolveUserState(userState);
|
|
1220
1263
|
await session.fetchCurrentState();
|
|
1221
|
-
(
|
|
1264
|
+
(_a = options.onPendingRequestsChange) == null ? void 0 : _a.call(options, session.getPendingRequests());
|
|
1222
1265
|
if (threadContextRef.current.currentThreadId === threadId) {
|
|
1223
1266
|
setIsRunning(session.getIsProcessing());
|
|
1224
1267
|
}
|
|
@@ -1235,10 +1278,8 @@ function useRuntimeOrchestrator(aomiClient, options) {
|
|
|
1235
1278
|
);
|
|
1236
1279
|
const sendMessage = useCallback5(
|
|
1237
1280
|
async (text, threadId) => {
|
|
1238
|
-
var _a
|
|
1281
|
+
var _a;
|
|
1239
1282
|
const session = getSession(threadId);
|
|
1240
|
-
const userState = (_a = options.getUserState) == null ? void 0 : _a.call(options);
|
|
1241
|
-
if (userState) session.resolveUserState(userState);
|
|
1242
1283
|
const existingMessages = threadContextRef.current.getThreadMessages(threadId);
|
|
1243
1284
|
const userMessage = {
|
|
1244
1285
|
role: "user",
|
|
@@ -1253,7 +1294,7 @@ function useRuntimeOrchestrator(aomiClient, options) {
|
|
|
1253
1294
|
lastActiveAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1254
1295
|
});
|
|
1255
1296
|
await session.sendAsync(text);
|
|
1256
|
-
(
|
|
1297
|
+
(_a = options.onPendingRequestsChange) == null ? void 0 : _a.call(options, session.getPendingRequests());
|
|
1257
1298
|
},
|
|
1258
1299
|
[getSession]
|
|
1259
1300
|
);
|
|
@@ -1525,8 +1566,41 @@ function useWalletHandler({
|
|
|
1525
1566
|
};
|
|
1526
1567
|
}
|
|
1527
1568
|
|
|
1569
|
+
// packages/react/src/runtime/user-state-provider.tsx
|
|
1570
|
+
import { useEffect as useEffect3, useRef as useRef7 } from "react";
|
|
1571
|
+
import { Fragment, jsx as jsx6 } from "react/jsx-runtime";
|
|
1572
|
+
function stableStateString(state) {
|
|
1573
|
+
return JSON.stringify(state != null ? state : {});
|
|
1574
|
+
}
|
|
1575
|
+
function RuntimeUserStateProvider({
|
|
1576
|
+
children,
|
|
1577
|
+
sessionManager,
|
|
1578
|
+
getUserState,
|
|
1579
|
+
onUserStateChange
|
|
1580
|
+
}) {
|
|
1581
|
+
const lastSerializedStateRef = useRef7("");
|
|
1582
|
+
useEffect3(() => {
|
|
1583
|
+
const applyToSessions = (next) => {
|
|
1584
|
+
const serialized = stableStateString(next);
|
|
1585
|
+
if (serialized === lastSerializedStateRef.current) {
|
|
1586
|
+
return;
|
|
1587
|
+
}
|
|
1588
|
+
lastSerializedStateRef.current = serialized;
|
|
1589
|
+
sessionManager.forEach((session) => {
|
|
1590
|
+
session.resolveUserState(next);
|
|
1591
|
+
});
|
|
1592
|
+
};
|
|
1593
|
+
applyToSessions(getUserState());
|
|
1594
|
+
const unsubscribe = onUserStateChange((next) => {
|
|
1595
|
+
applyToSessions(next);
|
|
1596
|
+
});
|
|
1597
|
+
return unsubscribe;
|
|
1598
|
+
}, [getUserState, onUserStateChange, sessionManager]);
|
|
1599
|
+
return /* @__PURE__ */ jsx6(Fragment, { children });
|
|
1600
|
+
}
|
|
1601
|
+
|
|
1528
1602
|
// packages/react/src/runtime/core.tsx
|
|
1529
|
-
import { jsx as
|
|
1603
|
+
import { jsx as jsx7 } from "react/jsx-runtime";
|
|
1530
1604
|
function AomiRuntimeCore({
|
|
1531
1605
|
children,
|
|
1532
1606
|
aomiClient
|
|
@@ -1536,7 +1610,7 @@ function AomiRuntimeCore({
|
|
|
1536
1610
|
const notificationContext = useNotification();
|
|
1537
1611
|
const { user, onUserStateChange, getUserState } = useUser();
|
|
1538
1612
|
const { getControlState, getCurrentThreadApp } = useControl();
|
|
1539
|
-
const sessionManagerRef =
|
|
1613
|
+
const sessionManagerRef = useRef8(null);
|
|
1540
1614
|
const walletHandler = useWalletHandler({
|
|
1541
1615
|
getSession: () => {
|
|
1542
1616
|
var _a;
|
|
@@ -1577,8 +1651,8 @@ function AomiRuntimeCore({
|
|
|
1577
1651
|
},
|
|
1578
1652
|
[getUserState]
|
|
1579
1653
|
);
|
|
1580
|
-
const lastWalletStateRef =
|
|
1581
|
-
|
|
1654
|
+
const lastWalletStateRef = useRef8(walletSnapshot(getUserState()));
|
|
1655
|
+
useEffect4(() => {
|
|
1582
1656
|
lastWalletStateRef.current = walletSnapshot(getUserState());
|
|
1583
1657
|
const unsubscribe = onUserStateChange(async (newUser) => {
|
|
1584
1658
|
const nextWalletState = walletSnapshot(newUser);
|
|
@@ -1602,10 +1676,10 @@ function AomiRuntimeCore({
|
|
|
1602
1676
|
getUserState,
|
|
1603
1677
|
walletSnapshot
|
|
1604
1678
|
]);
|
|
1605
|
-
const threadContextRef =
|
|
1679
|
+
const threadContextRef = useRef8(threadContext);
|
|
1606
1680
|
threadContextRef.current = threadContext;
|
|
1607
|
-
const remoteThreadIdsRef =
|
|
1608
|
-
const warmedThreadIdsRef =
|
|
1681
|
+
const remoteThreadIdsRef = useRef8(/* @__PURE__ */ new Set());
|
|
1682
|
+
const warmedThreadIdsRef = useRef8(/* @__PURE__ */ new Set());
|
|
1609
1683
|
const warmThread = useCallback7(
|
|
1610
1684
|
async (threadId) => {
|
|
1611
1685
|
if (!remoteThreadIdsRef.current.has(threadId) || warmedThreadIdsRef.current.has(threadId)) {
|
|
@@ -1620,7 +1694,7 @@ function AomiRuntimeCore({
|
|
|
1620
1694
|
},
|
|
1621
1695
|
[aomiClientRef, getUserState]
|
|
1622
1696
|
);
|
|
1623
|
-
|
|
1697
|
+
useEffect4(() => {
|
|
1624
1698
|
const unsubscribe = eventContext.subscribe(
|
|
1625
1699
|
"user_state_request",
|
|
1626
1700
|
() => {
|
|
@@ -1635,7 +1709,7 @@ function AomiRuntimeCore({
|
|
|
1635
1709
|
);
|
|
1636
1710
|
return unsubscribe;
|
|
1637
1711
|
}, [eventContext, threadContext.currentThreadId, getSession, getUserState]);
|
|
1638
|
-
|
|
1712
|
+
useEffect4(() => {
|
|
1639
1713
|
const threadId = threadContext.currentThreadId;
|
|
1640
1714
|
let cancelled = false;
|
|
1641
1715
|
void (async () => {
|
|
@@ -1648,7 +1722,7 @@ function AomiRuntimeCore({
|
|
|
1648
1722
|
cancelled = true;
|
|
1649
1723
|
};
|
|
1650
1724
|
}, [ensureInitialState, threadContext.currentThreadId, warmThread]);
|
|
1651
|
-
|
|
1725
|
+
useEffect4(() => {
|
|
1652
1726
|
const threadId = threadContext.currentThreadId;
|
|
1653
1727
|
const currentMeta = threadContext.getThreadMetadata(threadId);
|
|
1654
1728
|
if (currentMeta && currentMeta.control.isProcessing !== isRunning) {
|
|
@@ -1662,7 +1736,7 @@ function AomiRuntimeCore({
|
|
|
1662
1736
|
const currentMessages = threadContext.getThreadMessages(
|
|
1663
1737
|
threadContext.currentThreadId
|
|
1664
1738
|
);
|
|
1665
|
-
|
|
1739
|
+
useEffect4(() => {
|
|
1666
1740
|
const userAddress = UserState3.isConnected(user) ? UserState3.address(user) : void 0;
|
|
1667
1741
|
if (!userAddress) {
|
|
1668
1742
|
remoteThreadIdsRef.current.clear();
|
|
@@ -1731,7 +1805,7 @@ function AomiRuntimeCore({
|
|
|
1731
1805
|
threadContext.allThreadsMetadata
|
|
1732
1806
|
]
|
|
1733
1807
|
);
|
|
1734
|
-
|
|
1808
|
+
useEffect4(() => {
|
|
1735
1809
|
const showToolNotification = (eventType) => (event) => {
|
|
1736
1810
|
const payload = event.payload;
|
|
1737
1811
|
const toolName = typeof (payload == null ? void 0 : payload.tool_name) === "string" ? payload.tool_name : void 0;
|
|
@@ -1756,7 +1830,7 @@ function AomiRuntimeCore({
|
|
|
1756
1830
|
unsubscribeComplete();
|
|
1757
1831
|
};
|
|
1758
1832
|
}, [eventContext, notificationContext]);
|
|
1759
|
-
|
|
1833
|
+
useEffect4(() => {
|
|
1760
1834
|
const unsubscribe = eventContext.subscribe("system_notice", (_event) => {
|
|
1761
1835
|
});
|
|
1762
1836
|
return unsubscribe;
|
|
@@ -1779,7 +1853,7 @@ function AomiRuntimeCore({
|
|
|
1779
1853
|
convertMessage: (msg) => msg,
|
|
1780
1854
|
adapters: { threadList: threadListAdapter }
|
|
1781
1855
|
});
|
|
1782
|
-
|
|
1856
|
+
useEffect4(() => {
|
|
1783
1857
|
return () => {
|
|
1784
1858
|
sessionManager.closeAll();
|
|
1785
1859
|
};
|
|
@@ -1893,17 +1967,25 @@ function AomiRuntimeCore({
|
|
|
1893
1967
|
eventContext
|
|
1894
1968
|
]
|
|
1895
1969
|
);
|
|
1896
|
-
return /* @__PURE__ */
|
|
1970
|
+
return /* @__PURE__ */ jsx7(AomiRuntimeApiProvider, { value: aomiRuntimeApi, children: /* @__PURE__ */ jsx7(
|
|
1971
|
+
RuntimeUserStateProvider,
|
|
1972
|
+
{
|
|
1973
|
+
sessionManager,
|
|
1974
|
+
getUserState: userContext.getUserState,
|
|
1975
|
+
onUserStateChange: userContext.onUserStateChange,
|
|
1976
|
+
children: /* @__PURE__ */ jsx7(AssistantRuntimeProvider, { runtime, children })
|
|
1977
|
+
}
|
|
1978
|
+
) });
|
|
1897
1979
|
}
|
|
1898
1980
|
|
|
1899
1981
|
// packages/react/src/runtime/aomi-runtime.tsx
|
|
1900
|
-
import { jsx as
|
|
1982
|
+
import { jsx as jsx8 } from "react/jsx-runtime";
|
|
1901
1983
|
function AomiRuntimeProvider({
|
|
1902
1984
|
children,
|
|
1903
1985
|
backendUrl = "http://localhost:8080"
|
|
1904
1986
|
}) {
|
|
1905
1987
|
const aomiClient = useMemo3(() => new AomiClient({ baseUrl: backendUrl }), [backendUrl]);
|
|
1906
|
-
return /* @__PURE__ */
|
|
1988
|
+
return /* @__PURE__ */ jsx8(ThreadContextProvider, { children: /* @__PURE__ */ jsx8(NotificationContextProvider, { children: /* @__PURE__ */ jsx8(UserContextProvider, { children: /* @__PURE__ */ jsx8(AomiRuntimeInner, { aomiClient, children }) }) }) });
|
|
1907
1989
|
}
|
|
1908
1990
|
function AomiRuntimeInner({
|
|
1909
1991
|
children,
|
|
@@ -1912,7 +1994,7 @@ function AomiRuntimeInner({
|
|
|
1912
1994
|
var _a;
|
|
1913
1995
|
const threadContext = useThreadContext();
|
|
1914
1996
|
const { user } = useUser();
|
|
1915
|
-
return /* @__PURE__ */
|
|
1997
|
+
return /* @__PURE__ */ jsx8(
|
|
1916
1998
|
ControlContextProvider,
|
|
1917
1999
|
{
|
|
1918
2000
|
aomiClient,
|
|
@@ -1920,12 +2002,12 @@ function AomiRuntimeInner({
|
|
|
1920
2002
|
publicKey: UserState4.isConnected(user) ? (_a = UserState4.address(user)) != null ? _a : void 0 : void 0,
|
|
1921
2003
|
getThreadMetadata: threadContext.getThreadMetadata,
|
|
1922
2004
|
updateThreadMetadata: threadContext.updateThreadMetadata,
|
|
1923
|
-
children: /* @__PURE__ */
|
|
2005
|
+
children: /* @__PURE__ */ jsx8(
|
|
1924
2006
|
EventContextProvider,
|
|
1925
2007
|
{
|
|
1926
2008
|
aomiClient,
|
|
1927
2009
|
sessionId: threadContext.currentThreadId,
|
|
1928
|
-
children: /* @__PURE__ */
|
|
2010
|
+
children: /* @__PURE__ */ jsx8(AomiRuntimeCore, { aomiClient, children })
|
|
1929
2011
|
}
|
|
1930
2012
|
)
|
|
1931
2013
|
}
|
|
@@ -1933,7 +2015,7 @@ function AomiRuntimeInner({
|
|
|
1933
2015
|
}
|
|
1934
2016
|
|
|
1935
2017
|
// packages/react/src/handlers/notification-handler.ts
|
|
1936
|
-
import { useCallback as useCallback8, useEffect as
|
|
2018
|
+
import { useCallback as useCallback8, useEffect as useEffect5, useState as useState6 } from "react";
|
|
1937
2019
|
var notificationIdCounter2 = 0;
|
|
1938
2020
|
function generateNotificationId() {
|
|
1939
2021
|
return `notif-${Date.now()}-${++notificationIdCounter2}`;
|
|
@@ -1943,7 +2025,7 @@ function useNotificationHandler({
|
|
|
1943
2025
|
} = {}) {
|
|
1944
2026
|
const { subscribe } = useEventContext();
|
|
1945
2027
|
const [notifications, setNotifications] = useState6([]);
|
|
1946
|
-
|
|
2028
|
+
useEffect5(() => {
|
|
1947
2029
|
const unsubscribe = subscribe("notification", (event) => {
|
|
1948
2030
|
var _a, _b;
|
|
1949
2031
|
const payload = event.payload;
|
|
@@ -1977,16 +2059,24 @@ export {
|
|
|
1977
2059
|
AomiClient2 as AomiClient,
|
|
1978
2060
|
AomiRuntimeProvider,
|
|
1979
2061
|
ControlContextProvider,
|
|
2062
|
+
DISABLED_PROVIDER_STATE,
|
|
1980
2063
|
EventContextProvider,
|
|
1981
2064
|
NotificationContextProvider,
|
|
2065
|
+
RuntimeUserStateProvider,
|
|
1982
2066
|
SUPPORTED_CHAINS,
|
|
1983
2067
|
ThreadContextProvider,
|
|
1984
2068
|
UserContextProvider,
|
|
2069
|
+
aaModeFromExecutionKind,
|
|
1985
2070
|
cn,
|
|
2071
|
+
executeWalletCalls,
|
|
1986
2072
|
formatAddress,
|
|
1987
2073
|
getChainInfo,
|
|
1988
2074
|
getNetworkName,
|
|
2075
|
+
hydrateTxPayloadFromUserState,
|
|
1989
2076
|
initThreadControl,
|
|
2077
|
+
parseChainId,
|
|
2078
|
+
toAAWalletCall,
|
|
2079
|
+
toAAWalletCalls,
|
|
1990
2080
|
toViemSignTypedDataArgs,
|
|
1991
2081
|
useAomiRuntime,
|
|
1992
2082
|
useControl,
|