@aomi-labs/react 0.3.5 → 0.3.6

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.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { WalletTxPayload, WalletEip712Payload, AomiSystemEvent, AomiClient } from '@aomi-labs/client';
2
- export { AomiChatResponse, AomiClient, AomiClientOptions, AomiCreateThreadResponse, AomiInterruptResponse, AomiMessage, AomiSSEEvent, AomiStateResponse, AomiSystemEvent, AomiSystemResponse, AomiThread, WalletEip712Payload, WalletTxPayload, toViemSignTypedDataArgs } from '@aomi-labs/client';
1
+ import { AomiClient, Session, WalletRequest } from '@aomi-labs/client';
2
+ export { AomiChatResponse, AomiClient, AomiClientOptions, AomiCreateThreadResponse, AomiInterruptResponse, AomiMessage, AomiSSEEvent, AomiStateResponse, AomiSystemEvent, AomiSystemResponse, AomiThread, WalletEip712Payload, WalletRequest, WalletTxPayload, 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';
@@ -80,24 +80,37 @@ type InboundEvent = {
80
80
  type: string;
81
81
  sessionId: string;
82
82
  payload?: unknown;
83
- status: "pending" | "fetched";
84
- timestamp: number;
85
- };
86
- type OutboundEvent = {
87
- type: string;
88
- sessionId: string;
89
- payload: unknown;
90
- timestamp: number;
91
83
  };
92
84
  type SSEStatus = "connected" | "connecting" | "disconnected";
93
85
  type EventSubscriber = (event: InboundEvent) => void;
94
- type EventBuffer = {
95
- inboundQueue: InboundEvent[];
96
- outboundQueue: OutboundEvent[];
86
+ type EventContext = {
87
+ /** Subscribe to events by type. Returns unsubscribe function. */
88
+ subscribe: (type: string, callback: EventSubscriber) => () => void;
89
+ /** Dispatch an event to all matching subscribers (used by orchestrator) */
90
+ dispatch: (event: InboundEvent) => void;
91
+ /** Send an outbound system message to backend */
92
+ sendOutboundSystem: (event: {
93
+ type: string;
94
+ sessionId: string;
95
+ payload: unknown;
96
+ }) => Promise<void>;
97
+ /** Current SSE connection status */
97
98
  sseStatus: SSEStatus;
98
- lastEventId: string | null;
99
- subscribers: Map<string, Set<EventSubscriber>>;
100
99
  };
100
+ declare function useEventContext(): EventContext;
101
+ type EventContextProviderProps = {
102
+ children: ReactNode;
103
+ aomiClient: AomiClient;
104
+ sessionId: string;
105
+ };
106
+ /**
107
+ * Simplified EventContext — a pure pub/sub relay.
108
+ *
109
+ * SSE subscription and system event unwrapping are now handled by ClientSession
110
+ * in the orchestrator. This provider just maintains the subscriber registry
111
+ * and sendOutboundSystem for direct system messages.
112
+ */
113
+ declare function EventContextProvider({ children, aomiClient, sessionId, }: EventContextProviderProps): react_jsx_runtime.JSX.Element;
101
114
 
102
115
  type NotificationType = "notice" | "success" | "error" | "wallet";
103
116
  type Notification$1 = {
@@ -127,40 +140,26 @@ declare function NotificationContextProvider({ children, }: NotificationContextP
127
140
 
128
141
  type WalletRequestKind = "transaction" | "eip712_sign";
129
142
  type WalletRequestStatus = "pending" | "processing";
130
- type WalletRequest = {
131
- id: string;
132
- kind: WalletRequestKind;
133
- payload: WalletTxPayload | WalletEip712Payload;
134
- status: WalletRequestStatus;
135
- timestamp: number;
136
- };
137
- type WalletBuffer = {
138
- queue: WalletRequest[];
139
- nextId: number;
140
- };
141
-
142
143
  type WalletRequestResult = {
143
144
  txHash?: string;
144
145
  signature?: string;
145
146
  amount?: string;
146
147
  };
147
148
  type WalletHandlerConfig = {
148
- sessionId: string;
149
- /** Called after a wallet request is resolved/rejected and the outbound event is sent.
150
- * Used by core.tsx to start polling for the AI's response. */
151
- onRequestComplete?: () => void;
149
+ /** Get the ClientSession for the current thread. */
150
+ getSession: () => Session | undefined;
152
151
  };
153
152
  type WalletHandlerApi = {
154
153
  /** All queued wallet requests (tx + eip712) */
155
154
  pendingRequests: WalletRequest[];
156
- /** Mark a request as being processed */
157
- startProcessing: (id: string) => void;
158
- /** Complete a request successfully — dequeues + sends response to backend */
155
+ /** Enqueue a wallet request (called by orchestrator on ClientSession events) */
156
+ enqueueRequest: (request: WalletRequest) => void;
157
+ /** Complete a request successfully — sends response to backend via ClientSession */
159
158
  resolveRequest: (id: string, result: WalletRequestResult) => void;
160
- /** Fail a request — dequeues + sends error to backend */
159
+ /** Fail a request — sends error to backend via ClientSession */
161
160
  rejectRequest: (id: string, error?: string) => void;
162
161
  };
163
- declare function useWalletHandler({ sessionId, onRequestComplete, }: WalletHandlerConfig): WalletHandlerApi;
162
+ declare function useWalletHandler({ getSession, }: WalletHandlerConfig): WalletHandlerApi;
164
163
 
165
164
  type AomiRuntimeApi = {
166
165
  /** Current user state (wallet connection, address, chain, etc.) */
@@ -220,7 +219,11 @@ type AomiRuntimeApi = {
220
219
  /** Subscribe to inbound events by type. Returns unsubscribe function. */
221
220
  subscribe: (type: string, callback: EventSubscriber) => () => void;
222
221
  /** Send a system command to the backend */
223
- sendSystemCommand: (event: Omit<OutboundEvent, "timestamp">) => Promise<void>;
222
+ sendSystemCommand: (event: {
223
+ type: string;
224
+ sessionId: string;
225
+ payload: unknown;
226
+ }) => Promise<void>;
224
227
  /** Current SSE connection status */
225
228
  sseStatus: SSEStatus;
226
229
  };
@@ -254,24 +257,6 @@ type AomiRuntimeApi = {
254
257
  */
255
258
  declare function useAomiRuntime(): AomiRuntimeApi;
256
259
 
257
- type EventContext = {
258
- /** Subscribe to inbound events by type. Returns unsubscribe function. */
259
- subscribe: (type: string, callback: EventSubscriber) => () => void;
260
- /** Send an outbound event to backend immediately */
261
- sendOutboundSystem: (event: Omit<OutboundEvent, "timestamp">) => Promise<void>;
262
- /** Dispatch system events from HTTP polling into the event buffer */
263
- dispatchInboundSystem: (sessionId: string, events: AomiSystemEvent[]) => void;
264
- /** Current SSE connection status */
265
- sseStatus: SSEStatus;
266
- };
267
- declare function useEventContext(): EventContext;
268
- type EventContextProviderProps = {
269
- children: ReactNode;
270
- aomiClient: AomiClient;
271
- sessionId: string;
272
- };
273
- declare function EventContextProvider({ children, aomiClient, sessionId, }: EventContextProviderProps): react_jsx_runtime.JSX.Element;
274
-
275
260
  type Notification = {
276
261
  id: string;
277
262
  type: string;
@@ -384,4 +369,4 @@ type ControlContextProviderProps = {
384
369
  };
385
370
  declare function ControlContextProvider({ children, aomiClient, sessionId, publicKey, getThreadMetadata, updateThreadMetadata, }: ControlContextProviderProps): react_jsx_runtime.JSX.Element;
386
371
 
387
- export { type AomiRuntimeApi, AomiRuntimeProvider, type AomiRuntimeProviderProps, type ChainInfo, type ControlContextApi, ControlContextProvider, type ControlContextProviderProps, type ControlState, type EventBuffer, 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 OutboundEvent, type SSEStatus, SUPPORTED_CHAINS, type NotificationData as ShowNotificationParams, type ThreadContext, ThreadContextProvider, type ThreadControlState, type ThreadMetadata, type UserConfig, UserContextProvider, type UserState, type WalletBuffer, type WalletHandlerApi, type WalletHandlerConfig, type WalletRequest, type WalletRequestKind, type WalletRequestResult, type WalletRequestStatus, cn, formatAddress, getChainInfo, getNetworkName, initThreadControl, useAomiRuntime, useControl, useCurrentThreadMessages, useCurrentThreadMetadata, useEventContext, useNotification, useNotificationHandler, useThreadContext, useUser, useWalletHandler };
372
+ 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 ThreadContext, ThreadContextProvider, type ThreadControlState, type ThreadMetadata, type UserConfig, UserContextProvider, type UserState, type WalletHandlerApi, type WalletHandlerConfig, type WalletRequestKind, type WalletRequestResult, 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 { WalletTxPayload, WalletEip712Payload, AomiSystemEvent, AomiClient } from '@aomi-labs/client';
2
- export { AomiChatResponse, AomiClient, AomiClientOptions, AomiCreateThreadResponse, AomiInterruptResponse, AomiMessage, AomiSSEEvent, AomiStateResponse, AomiSystemEvent, AomiSystemResponse, AomiThread, WalletEip712Payload, WalletTxPayload, toViemSignTypedDataArgs } from '@aomi-labs/client';
1
+ import { AomiClient, Session, WalletRequest } from '@aomi-labs/client';
2
+ export { AomiChatResponse, AomiClient, AomiClientOptions, AomiCreateThreadResponse, AomiInterruptResponse, AomiMessage, AomiSSEEvent, AomiStateResponse, AomiSystemEvent, AomiSystemResponse, AomiThread, WalletEip712Payload, WalletRequest, WalletTxPayload, 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';
@@ -80,24 +80,37 @@ type InboundEvent = {
80
80
  type: string;
81
81
  sessionId: string;
82
82
  payload?: unknown;
83
- status: "pending" | "fetched";
84
- timestamp: number;
85
- };
86
- type OutboundEvent = {
87
- type: string;
88
- sessionId: string;
89
- payload: unknown;
90
- timestamp: number;
91
83
  };
92
84
  type SSEStatus = "connected" | "connecting" | "disconnected";
93
85
  type EventSubscriber = (event: InboundEvent) => void;
94
- type EventBuffer = {
95
- inboundQueue: InboundEvent[];
96
- outboundQueue: OutboundEvent[];
86
+ type EventContext = {
87
+ /** Subscribe to events by type. Returns unsubscribe function. */
88
+ subscribe: (type: string, callback: EventSubscriber) => () => void;
89
+ /** Dispatch an event to all matching subscribers (used by orchestrator) */
90
+ dispatch: (event: InboundEvent) => void;
91
+ /** Send an outbound system message to backend */
92
+ sendOutboundSystem: (event: {
93
+ type: string;
94
+ sessionId: string;
95
+ payload: unknown;
96
+ }) => Promise<void>;
97
+ /** Current SSE connection status */
97
98
  sseStatus: SSEStatus;
98
- lastEventId: string | null;
99
- subscribers: Map<string, Set<EventSubscriber>>;
100
99
  };
100
+ declare function useEventContext(): EventContext;
101
+ type EventContextProviderProps = {
102
+ children: ReactNode;
103
+ aomiClient: AomiClient;
104
+ sessionId: string;
105
+ };
106
+ /**
107
+ * Simplified EventContext — a pure pub/sub relay.
108
+ *
109
+ * SSE subscription and system event unwrapping are now handled by ClientSession
110
+ * in the orchestrator. This provider just maintains the subscriber registry
111
+ * and sendOutboundSystem for direct system messages.
112
+ */
113
+ declare function EventContextProvider({ children, aomiClient, sessionId, }: EventContextProviderProps): react_jsx_runtime.JSX.Element;
101
114
 
102
115
  type NotificationType = "notice" | "success" | "error" | "wallet";
103
116
  type Notification$1 = {
@@ -127,40 +140,26 @@ declare function NotificationContextProvider({ children, }: NotificationContextP
127
140
 
128
141
  type WalletRequestKind = "transaction" | "eip712_sign";
129
142
  type WalletRequestStatus = "pending" | "processing";
130
- type WalletRequest = {
131
- id: string;
132
- kind: WalletRequestKind;
133
- payload: WalletTxPayload | WalletEip712Payload;
134
- status: WalletRequestStatus;
135
- timestamp: number;
136
- };
137
- type WalletBuffer = {
138
- queue: WalletRequest[];
139
- nextId: number;
140
- };
141
-
142
143
  type WalletRequestResult = {
143
144
  txHash?: string;
144
145
  signature?: string;
145
146
  amount?: string;
146
147
  };
147
148
  type WalletHandlerConfig = {
148
- sessionId: string;
149
- /** Called after a wallet request is resolved/rejected and the outbound event is sent.
150
- * Used by core.tsx to start polling for the AI's response. */
151
- onRequestComplete?: () => void;
149
+ /** Get the ClientSession for the current thread. */
150
+ getSession: () => Session | undefined;
152
151
  };
153
152
  type WalletHandlerApi = {
154
153
  /** All queued wallet requests (tx + eip712) */
155
154
  pendingRequests: WalletRequest[];
156
- /** Mark a request as being processed */
157
- startProcessing: (id: string) => void;
158
- /** Complete a request successfully — dequeues + sends response to backend */
155
+ /** Enqueue a wallet request (called by orchestrator on ClientSession events) */
156
+ enqueueRequest: (request: WalletRequest) => void;
157
+ /** Complete a request successfully — sends response to backend via ClientSession */
159
158
  resolveRequest: (id: string, result: WalletRequestResult) => void;
160
- /** Fail a request — dequeues + sends error to backend */
159
+ /** Fail a request — sends error to backend via ClientSession */
161
160
  rejectRequest: (id: string, error?: string) => void;
162
161
  };
163
- declare function useWalletHandler({ sessionId, onRequestComplete, }: WalletHandlerConfig): WalletHandlerApi;
162
+ declare function useWalletHandler({ getSession, }: WalletHandlerConfig): WalletHandlerApi;
164
163
 
165
164
  type AomiRuntimeApi = {
166
165
  /** Current user state (wallet connection, address, chain, etc.) */
@@ -220,7 +219,11 @@ type AomiRuntimeApi = {
220
219
  /** Subscribe to inbound events by type. Returns unsubscribe function. */
221
220
  subscribe: (type: string, callback: EventSubscriber) => () => void;
222
221
  /** Send a system command to the backend */
223
- sendSystemCommand: (event: Omit<OutboundEvent, "timestamp">) => Promise<void>;
222
+ sendSystemCommand: (event: {
223
+ type: string;
224
+ sessionId: string;
225
+ payload: unknown;
226
+ }) => Promise<void>;
224
227
  /** Current SSE connection status */
225
228
  sseStatus: SSEStatus;
226
229
  };
@@ -254,24 +257,6 @@ type AomiRuntimeApi = {
254
257
  */
255
258
  declare function useAomiRuntime(): AomiRuntimeApi;
256
259
 
257
- type EventContext = {
258
- /** Subscribe to inbound events by type. Returns unsubscribe function. */
259
- subscribe: (type: string, callback: EventSubscriber) => () => void;
260
- /** Send an outbound event to backend immediately */
261
- sendOutboundSystem: (event: Omit<OutboundEvent, "timestamp">) => Promise<void>;
262
- /** Dispatch system events from HTTP polling into the event buffer */
263
- dispatchInboundSystem: (sessionId: string, events: AomiSystemEvent[]) => void;
264
- /** Current SSE connection status */
265
- sseStatus: SSEStatus;
266
- };
267
- declare function useEventContext(): EventContext;
268
- type EventContextProviderProps = {
269
- children: ReactNode;
270
- aomiClient: AomiClient;
271
- sessionId: string;
272
- };
273
- declare function EventContextProvider({ children, aomiClient, sessionId, }: EventContextProviderProps): react_jsx_runtime.JSX.Element;
274
-
275
260
  type Notification = {
276
261
  id: string;
277
262
  type: string;
@@ -384,4 +369,4 @@ type ControlContextProviderProps = {
384
369
  };
385
370
  declare function ControlContextProvider({ children, aomiClient, sessionId, publicKey, getThreadMetadata, updateThreadMetadata, }: ControlContextProviderProps): react_jsx_runtime.JSX.Element;
386
371
 
387
- export { type AomiRuntimeApi, AomiRuntimeProvider, type AomiRuntimeProviderProps, type ChainInfo, type ControlContextApi, ControlContextProvider, type ControlContextProviderProps, type ControlState, type EventBuffer, 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 OutboundEvent, type SSEStatus, SUPPORTED_CHAINS, type NotificationData as ShowNotificationParams, type ThreadContext, ThreadContextProvider, type ThreadControlState, type ThreadMetadata, type UserConfig, UserContextProvider, type UserState, type WalletBuffer, type WalletHandlerApi, type WalletHandlerConfig, type WalletRequest, type WalletRequestKind, type WalletRequestResult, type WalletRequestStatus, cn, formatAddress, getChainInfo, getNetworkName, initThreadControl, useAomiRuntime, useControl, useCurrentThreadMessages, useCurrentThreadMetadata, useEventContext, useNotification, useNotificationHandler, useThreadContext, useUser, useWalletHandler };
372
+ 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 ThreadContext, ThreadContextProvider, type ThreadControlState, type ThreadMetadata, type UserConfig, UserContextProvider, type UserState, type WalletHandlerApi, type WalletHandlerConfig, type WalletRequestKind, type WalletRequestResult, type WalletRequestStatus, cn, formatAddress, getChainInfo, getNetworkName, initThreadControl, useAomiRuntime, useControl, useCurrentThreadMessages, useCurrentThreadMetadata, useEventContext, useNotification, useNotificationHandler, useThreadContext, useUser, useWalletHandler };