@aomi-labs/react 0.2.0 → 0.2.1

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 DELETED
@@ -1,385 +0,0 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { ReactNode, SetStateAction } from 'react';
3
- import { ThreadMessageLike } from '@assistant-ui/react';
4
- import { ClassValue } from 'clsx';
5
-
6
- interface AomiMessage {
7
- sender?: "user" | "agent" | "system" | string;
8
- content?: string;
9
- timestamp?: string;
10
- is_streaming?: boolean;
11
- tool_result?: [string, string] | null;
12
- }
13
- /**
14
- * GET /api/state
15
- * Fetches current session state including messages and processing status
16
- */
17
- interface ApiStateResponse {
18
- messages?: AomiMessage[] | null;
19
- system_events?: ApiSystemEvent[] | null;
20
- title?: string | null;
21
- is_processing?: boolean;
22
- }
23
- /**
24
- * POST /api/chat
25
- * Sends a chat message and returns updated session state
26
- */
27
- interface ApiChatResponse {
28
- messages?: AomiMessage[] | null;
29
- system_events?: ApiSystemEvent[] | null;
30
- title?: string | null;
31
- is_processing?: boolean;
32
- }
33
- /**
34
- * POST /api/system
35
- * Sends a system message and returns the response message
36
- */
37
- interface ApiSystemResponse {
38
- res?: AomiMessage | null;
39
- }
40
- /**
41
- * POST /api/interrupt
42
- * Interrupts current processing and returns updated session state
43
- */
44
- type ApiInterruptResponse = ApiChatResponse;
45
- /**
46
- * GET /api/sessions
47
- * Returns array of ApiThread
48
- */
49
- interface ApiThread {
50
- session_id: string;
51
- title: string;
52
- is_archived?: boolean;
53
- }
54
- /**
55
- * POST /api/sessions
56
- * Creates a new thread/session
57
- */
58
- interface ApiCreateThreadResponse {
59
- session_id: string;
60
- title?: string;
61
- }
62
- /**
63
- * Base SSE event - all events have session_id and type
64
- */
65
- type ApiSSEEvent = {
66
- type: "title_changed" | "tool_update" | "tool_complete" | "system_notice" | string;
67
- session_id: string;
68
- new_title?: string;
69
- [key: string]: unknown;
70
- };
71
- /**
72
- * Backend SystemEvent enum serializes as tagged JSON:
73
- * - InlineCall: {"InlineCall": {"type": "wallet_tx_request", "payload": {...}}}
74
- * - SystemNotice: {"SystemNotice": "message"}
75
- * - SystemError: {"SystemError": "message"}
76
- * - AsyncCallback: {"AsyncCallback": {...}} (not sent over HTTP)
77
- */
78
- type ApiSystemEvent = {
79
- InlineCall: {
80
- type: string;
81
- payload?: unknown;
82
- [key: string]: unknown;
83
- };
84
- } | {
85
- SystemNotice: string;
86
- } | {
87
- SystemError: string;
88
- } | {
89
- AsyncCallback: Record<string, unknown>;
90
- };
91
-
92
- type UserState = {
93
- address?: string;
94
- chainId?: number;
95
- isConnected: boolean;
96
- ensName?: string;
97
- };
98
- declare function useUser(): {
99
- user: UserState;
100
- setUser: (data: Partial<UserState>) => void;
101
- getUserState: () => UserState;
102
- onUserStateChange: (callback: (user: UserState) => void) => () => void;
103
- };
104
- declare function UserContextProvider({ children }: {
105
- children: ReactNode;
106
- }): react_jsx_runtime.JSX.Element;
107
-
108
- declare class BackendApi {
109
- private readonly backendUrl;
110
- private sseSubscriber;
111
- constructor(backendUrl: string);
112
- fetchState(sessionId: string, userState?: UserState): Promise<ApiStateResponse>;
113
- postChatMessage(sessionId: string, message: string, publicKey?: string): Promise<ApiChatResponse>;
114
- postSystemMessage(sessionId: string, message: string): Promise<ApiSystemResponse>;
115
- postInterrupt(sessionId: string): Promise<ApiInterruptResponse>;
116
- /**
117
- * Subscribe to SSE updates for a session.
118
- * Uses fetch streaming and reconnects on disconnects.
119
- * Returns an unsubscribe function.
120
- */
121
- subscribeSSE(sessionId: string, onUpdate: (event: ApiSSEEvent) => void, onError?: (error: unknown) => void): () => void;
122
- fetchThreads(publicKey: string): Promise<ApiThread[]>;
123
- fetchThread(sessionId: string): Promise<ApiThread>;
124
- createThread(threadId: string, publicKey?: string): Promise<ApiCreateThreadResponse>;
125
- archiveThread(sessionId: string): Promise<void>;
126
- unarchiveThread(sessionId: string): Promise<void>;
127
- deleteThread(sessionId: string): Promise<void>;
128
- renameThread(sessionId: string, newTitle: string): Promise<void>;
129
- getSystemEvents(sessionId: string, count?: number): Promise<ApiSystemEvent[]>;
130
- }
131
-
132
- type AomiRuntimeProviderProps = {
133
- children: ReactNode;
134
- backendUrl?: string;
135
- };
136
- declare function AomiRuntimeProvider({ children, backendUrl, }: Readonly<AomiRuntimeProviderProps>): react_jsx_runtime.JSX.Element;
137
-
138
- type ThreadContext = {
139
- currentThreadId: string;
140
- setCurrentThreadId: (id: string) => void;
141
- threadViewKey: number;
142
- bumpThreadViewKey: () => void;
143
- allThreads: Map<string, ThreadMessageLike[]>;
144
- setThreads: (updater: SetStateAction<Map<string, ThreadMessageLike[]>>) => void;
145
- allThreadsMetadata: Map<string, ThreadMetadata>;
146
- setThreadMetadata: (updater: SetStateAction<Map<string, ThreadMetadata>>) => void;
147
- threadCnt: number;
148
- setThreadCnt: (updater: SetStateAction<number>) => void;
149
- getThreadMessages: (threadId: string) => ThreadMessageLike[];
150
- setThreadMessages: (threadId: string, messages: ThreadMessageLike[]) => void;
151
- getThreadMetadata: (threadId: string) => ThreadMetadata | undefined;
152
- updateThreadMetadata: (threadId: string, updates: Partial<ThreadMetadata>) => void;
153
- };
154
- type ThreadContextProviderProps = {
155
- children: ReactNode;
156
- initialThreadId?: string;
157
- };
158
- declare function useThreadContext(): ThreadContext;
159
- declare function ThreadContextProvider({ children, initialThreadId, }: ThreadContextProviderProps): react_jsx_runtime.JSX.Element;
160
- declare function useCurrentThreadMessages(): ThreadMessageLike[];
161
- declare function useCurrentThreadMetadata(): ThreadMetadata | undefined;
162
-
163
- type ThreadStatus = "regular" | "archived" | "pending";
164
- type ThreadMetadata = {
165
- title: string;
166
- status: ThreadStatus;
167
- lastActiveAt?: string | number;
168
- };
169
-
170
- type InboundEvent = {
171
- type: string;
172
- sessionId: string;
173
- payload?: unknown;
174
- status: "pending" | "fetched";
175
- timestamp: number;
176
- };
177
- type OutboundEvent = {
178
- type: string;
179
- sessionId: string;
180
- payload: unknown;
181
- timestamp: number;
182
- };
183
- type SSEStatus = "connected" | "connecting" | "disconnected";
184
- type EventSubscriber = (event: InboundEvent) => void;
185
- type EventBuffer = {
186
- inboundQueue: InboundEvent[];
187
- outboundQueue: OutboundEvent[];
188
- sseStatus: SSEStatus;
189
- lastEventId: string | null;
190
- subscribers: Map<string, Set<EventSubscriber>>;
191
- };
192
-
193
- type NotificationType = "notice" | "success" | "error" | "wallet";
194
- type Notification$1 = {
195
- id: string;
196
- type: NotificationType;
197
- title: string;
198
- message?: string;
199
- duration?: number;
200
- timestamp: number;
201
- };
202
- type NotificationData = Omit<Notification$1, "id" | "timestamp">;
203
- type NotificationContextApi = {
204
- /** All active notifications */
205
- notifications: Notification$1[];
206
- /** Show a new notification */
207
- showNotification: (params: NotificationData) => string;
208
- /** Dismiss a notification by ID */
209
- dismissNotification: (id: string) => void;
210
- /** Clear all notifications */
211
- clearAll: () => void;
212
- };
213
- declare function useNotification(): NotificationContextApi;
214
- type NotificationContextProviderProps = {
215
- children: ReactNode;
216
- };
217
- declare function NotificationContextProvider({ children, }: NotificationContextProviderProps): react_jsx_runtime.JSX.Element;
218
-
219
- type AomiRuntimeApi = {
220
- /** Current user state (wallet connection, address, chain, etc.) */
221
- user: UserState;
222
- /** Get current user state synchronously (useful in callbacks) */
223
- getUserState: () => UserState;
224
- /** Update user state (partial updates merged with existing state) */
225
- setUser: (data: Partial<UserState>) => void;
226
- /** Subscribe to user state changes. Returns unsubscribe function. */
227
- onUserStateChange: (callback: (user: UserState) => void) => () => void;
228
- /** ID of the currently active thread */
229
- currentThreadId: string;
230
- /** Key that changes when thread view should remount (use for React key prop) */
231
- threadViewKey: number;
232
- /** Metadata for all threads (title, status, lastActiveAt) */
233
- threadMetadata: Map<string, ThreadMetadata>;
234
- /** Get metadata for a specific thread */
235
- getThreadMetadata: (threadId: string) => ThreadMetadata | undefined;
236
- /** Create a new thread and return its ID */
237
- createThread: () => Promise<string>;
238
- /** Delete a thread by ID */
239
- deleteThread: (threadId: string) => Promise<void>;
240
- /** Rename a thread */
241
- renameThread: (threadId: string, title: string) => Promise<void>;
242
- /** Archive a thread */
243
- archiveThread: (threadId: string) => Promise<void>;
244
- /** Switch to a thread. If thread doesn't exist, creates a new one. */
245
- selectThread: (threadId: string) => void;
246
- /** Whether the assistant is currently generating a response */
247
- isRunning: boolean;
248
- /** Get messages for a thread (defaults to currentThreadId) */
249
- getMessages: (threadId?: string) => ThreadMessageLike[];
250
- /** Send a message to the current thread */
251
- sendMessage: (text: string) => Promise<void>;
252
- /** Cancel the current generation */
253
- cancelGeneration: () => void;
254
- /** All active notifications */
255
- notifications: Notification$1[];
256
- /** Show a notification. Returns the notification ID. */
257
- showNotification: (params: NotificationData) => string;
258
- /** Dismiss a notification by ID */
259
- dismissNotification: (id: string) => void;
260
- /** Clear all notifications */
261
- clearAllNotifications: () => void;
262
- /** Subscribe to inbound events by type. Returns unsubscribe function. */
263
- subscribe: (type: string, callback: EventSubscriber) => () => void;
264
- /** Send a system command to the backend */
265
- sendSystemCommand: (event: Omit<OutboundEvent, "timestamp">) => void;
266
- /** Current SSE connection status */
267
- sseStatus: SSEStatus;
268
- };
269
- /**
270
- * Unified hook that provides access to all Aomi runtime APIs.
271
- *
272
- * This is the primary way to interact with the Aomi runtime from consumer code.
273
- * It combines user, thread, chat, notification, and event APIs into a single interface.
274
- *
275
- * @example
276
- * ```tsx
277
- * function MyComponent() {
278
- * const aomi = useAomiRuntime();
279
- *
280
- * // User API
281
- * const { user, setUser } = aomi;
282
- *
283
- * // Thread API
284
- * const { currentThreadId, createThread, selectThread } = aomi;
285
- *
286
- * // Chat API
287
- * const { isRunning, sendMessage, cancelGeneration } = aomi;
288
- *
289
- * // Notification API
290
- * const { showNotification } = aomi;
291
- *
292
- * // Event API
293
- * const { subscribe, sendSystemCommand } = aomi;
294
- * }
295
- * ```
296
- */
297
- declare function useAomiRuntime(): AomiRuntimeApi;
298
-
299
- type EventContext = {
300
- /** Subscribe to inbound events by type. Returns unsubscribe function. */
301
- subscribe: (type: string, callback: EventSubscriber) => () => void;
302
- /** Send an outbound event to backend immediately */
303
- sendOutboundSystem: (event: Omit<OutboundEvent, "timestamp">) => void;
304
- /** Dispatch system events from HTTP polling into the event buffer */
305
- dispatchInboundSystem: (sessionId: string, events: ApiSystemEvent[]) => void;
306
- /** Current SSE connection status */
307
- sseStatus: SSEStatus;
308
- };
309
- declare function useEventContext(): EventContext;
310
- type EventContextProviderProps = {
311
- children: ReactNode;
312
- backendApi: BackendApi;
313
- sessionId: string;
314
- };
315
- declare function EventContextProvider({ children, backendApi, sessionId, }: EventContextProviderProps): react_jsx_runtime.JSX.Element;
316
-
317
- type WalletTxRequest = {
318
- to: string;
319
- value?: string;
320
- data?: string;
321
- chainId?: number;
322
- };
323
- type WalletTxComplete = {
324
- txHash: string;
325
- status: "success" | "failed";
326
- amount?: string;
327
- token?: string;
328
- };
329
- type WalletConnectionStatus = "connected" | "disconnected";
330
- type WalletHandlerConfig = {
331
- sessionId: string;
332
- onTxRequest?: (request: WalletTxRequest) => void;
333
- };
334
- type WalletHanderApi = {
335
- /** Send transaction completion event to backend */
336
- sendTxComplete: (tx: WalletTxComplete) => void;
337
- /** Send wallet connection status change and update user state */
338
- sendConnectionChange: (status: WalletConnectionStatus, address?: string, chainId?: number) => void;
339
- /** Pending transaction requests from AI */
340
- pendingTxRequests: WalletTxRequest[];
341
- /** Clear a pending request after handling */
342
- clearTxRequest: (index: number) => void;
343
- };
344
- declare function useWalletHandler({ sessionId, onTxRequest, }: WalletHandlerConfig): WalletHanderApi;
345
-
346
- type Notification = {
347
- id: string;
348
- type: string;
349
- title: string;
350
- body?: unknown;
351
- handled: boolean;
352
- timestamp: number;
353
- sessionId: string;
354
- };
355
- type NotificationHandlerConfig = {
356
- /** Callback when new notification arrives */
357
- onNotification?: (notification: Notification) => void;
358
- };
359
- type NotificationApi = {
360
- /** All notifications */
361
- notifications: Notification[];
362
- /** Unhandled count */
363
- unhandledCount: number;
364
- /** Mark notification as handled */
365
- markDone: (id: string) => void;
366
- };
367
- declare function useNotificationHandler({ onNotification, }?: NotificationHandlerConfig): NotificationApi;
368
-
369
- /**
370
- * Utility function to merge Tailwind CSS classes with conflict resolution.
371
- * Combines clsx for conditional classes and tailwind-merge for deduplication.
372
- */
373
- declare function cn(...inputs: ClassValue[]): string;
374
- /**
375
- * User configuration props for footer components.
376
- * Provides user state and setter from UserContext.
377
- */
378
- type UserConfig = {
379
- user: UserState;
380
- setUser: (data: Partial<UserState>) => void;
381
- };
382
- declare const getNetworkName: (chainId: number | string | undefined) => string;
383
- declare const formatAddress: (addr?: string) => string;
384
-
385
- export { type AomiMessage, type AomiRuntimeApi, AomiRuntimeProvider, type AomiRuntimeProviderProps, type ApiChatResponse, type ApiCreateThreadResponse, type ApiInterruptResponse, type ApiSSEEvent, type ApiStateResponse, type ApiSystemEvent, type ApiSystemResponse, type ApiThread, BackendApi, type EventBuffer, type EventContext, EventContextProvider, type EventContextProviderProps, type EventSubscriber, type Notification as HandlerNotification, type InboundEvent, type Notification$1 as Notification, type NotificationApi, NotificationContextProvider, type NotificationContextProviderProps, type NotificationContextApi as NotificationContextValue, type NotificationHandlerConfig, type NotificationType, type OutboundEvent, type SSEStatus, type NotificationData as ShowNotificationParams, type ThreadContext, ThreadContextProvider, type ThreadMetadata, type UserConfig, UserContextProvider, type UserState, type UserState as WalletButtonState, type WalletConnectionStatus, type WalletHanderApi, type WalletHandlerConfig, type WalletTxComplete, type WalletTxRequest, cn, formatAddress, getNetworkName, useAomiRuntime, useCurrentThreadMessages, useCurrentThreadMetadata, useEventContext, useNotification, useNotificationHandler, useThreadContext, useUser, useWalletHandler };