@aomi-labs/react 0.2.4 → 0.3.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 CHANGED
@@ -1,93 +1,15 @@
1
+ import { AomiSystemEvent, AomiClient } from '@aomi-labs/client';
2
+ export { AomiChatResponse, AomiClient, AomiClientOptions, AomiCreateThreadResponse, AomiInterruptResponse, AomiMessage, AomiSSEEvent, AomiStateResponse, AomiSystemEvent, AomiSystemResponse, AomiThread } from '@aomi-labs/client';
1
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
4
  import { ReactNode, SetStateAction } from 'react';
3
5
  import { ThreadMessageLike } from '@assistant-ui/react';
4
6
  import { ClassValue } from 'clsx';
5
7
 
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>;
8
+ type AomiRuntimeProviderProps = {
9
+ children: ReactNode;
10
+ backendUrl?: string;
90
11
  };
12
+ declare function AomiRuntimeProvider({ children, backendUrl, }: Readonly<AomiRuntimeProviderProps>): react_jsx_runtime.JSX.Element;
91
13
 
92
14
  type UserState = {
93
15
  address?: string;
@@ -105,53 +27,6 @@ declare function UserContextProvider({ children }: {
105
27
  children: ReactNode;
106
28
  }): react_jsx_runtime.JSX.Element;
107
29
 
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, namespace: string, publicKey?: string, apiKey?: string, userState?: UserState): 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
- * Get allowed namespaces for the current request context.
132
- */
133
- getNamespaces(sessionId: string, publicKey?: string, apiKey?: string): Promise<string[]>;
134
- /**
135
- * Get available models.
136
- */
137
- getModels(sessionId: string): Promise<string[]>;
138
- /**
139
- * Set the model selection for a session.
140
- */
141
- setModel(sessionId: string, rig: string, namespace?: string, apiKey?: string): Promise<{
142
- success: boolean;
143
- rig: string;
144
- baml: string;
145
- created: boolean;
146
- }>;
147
- }
148
-
149
- type AomiRuntimeProviderProps = {
150
- children: ReactNode;
151
- backendUrl?: string;
152
- };
153
- declare function AomiRuntimeProvider({ children, backendUrl, }: Readonly<AomiRuntimeProviderProps>): react_jsx_runtime.JSX.Element;
154
-
155
30
  type ThreadContext = {
156
31
  currentThreadId: string;
157
32
  setCurrentThreadId: (id: string) => void;
@@ -177,12 +52,12 @@ declare function ThreadContextProvider({ children, initialThreadId, }: ThreadCon
177
52
  declare function useCurrentThreadMessages(): ThreadMessageLike[];
178
53
  declare function useCurrentThreadMetadata(): ThreadMetadata | undefined;
179
54
 
180
- type ThreadStatus = "regular" | "archived" | "pending";
55
+ type ThreadStatus = "regular" | "archived";
181
56
  type ThreadControlState = {
182
57
  /** Selected model for this thread (human-readable label) */
183
58
  model: string | null;
184
- /** Selected namespace for this thread */
185
- namespace: string | null;
59
+ /** Selected app for this thread */
60
+ app: string | null;
186
61
  /** Whether control state has changed but chat hasn't started yet */
187
62
  controlDirty: boolean;
188
63
  /** Whether this thread is currently processing (assistant generating) */
@@ -192,7 +67,7 @@ type ThreadMetadata = {
192
67
  title: string;
193
68
  status: ThreadStatus;
194
69
  lastActiveAt?: string | number;
195
- /** Per-thread control state (model, namespace selection) */
70
+ /** Per-thread control state (model, app selection) */
196
71
  control: ThreadControlState;
197
72
  };
198
73
  /** Create default control state for a new thread */
@@ -247,6 +122,63 @@ type NotificationContextProviderProps = {
247
122
  };
248
123
  declare function NotificationContextProvider({ children, }: NotificationContextProviderProps): react_jsx_runtime.JSX.Element;
249
124
 
125
+ type WalletRequestKind = "transaction" | "eip712_sign";
126
+ type WalletTxPayload = {
127
+ to: string;
128
+ value?: string;
129
+ data?: string;
130
+ chainId?: number;
131
+ };
132
+ type WalletEip712Payload = {
133
+ typed_data?: {
134
+ domain?: {
135
+ chainId?: number | string;
136
+ };
137
+ types?: Record<string, Array<{
138
+ name: string;
139
+ type: string;
140
+ }>>;
141
+ primaryType?: string;
142
+ message?: Record<string, unknown>;
143
+ };
144
+ description?: string;
145
+ };
146
+ type WalletRequestStatus = "pending" | "processing";
147
+ type WalletRequest = {
148
+ id: string;
149
+ kind: WalletRequestKind;
150
+ payload: WalletTxPayload | WalletEip712Payload;
151
+ status: WalletRequestStatus;
152
+ timestamp: number;
153
+ };
154
+ type WalletBuffer = {
155
+ queue: WalletRequest[];
156
+ nextId: number;
157
+ };
158
+
159
+ type WalletRequestResult = {
160
+ txHash?: string;
161
+ signature?: string;
162
+ amount?: string;
163
+ };
164
+ type WalletHandlerConfig = {
165
+ sessionId: string;
166
+ /** Called after a wallet request is resolved/rejected and the outbound event is sent.
167
+ * Used by core.tsx to start polling for the AI's response. */
168
+ onRequestComplete?: () => void;
169
+ };
170
+ type WalletHandlerApi = {
171
+ /** All queued wallet requests (tx + eip712) */
172
+ pendingRequests: WalletRequest[];
173
+ /** Mark a request as being processed */
174
+ startProcessing: (id: string) => void;
175
+ /** Complete a request successfully — dequeues + sends response to backend */
176
+ resolveRequest: (id: string, result: WalletRequestResult) => void;
177
+ /** Fail a request — dequeues + sends error to backend */
178
+ rejectRequest: (id: string, error?: string) => void;
179
+ };
180
+ declare function useWalletHandler({ sessionId, onRequestComplete, }: WalletHandlerConfig): WalletHandlerApi;
181
+
250
182
  type AomiRuntimeApi = {
251
183
  /** Current user state (wallet connection, address, chain, etc.) */
252
184
  user: UserState;
@@ -290,10 +222,18 @@ type AomiRuntimeApi = {
290
222
  dismissNotification: (id: string) => void;
291
223
  /** Clear all notifications */
292
224
  clearAllNotifications: () => void;
225
+ /** All queued wallet requests (tx + eip712 signing) */
226
+ pendingWalletRequests: WalletRequest[];
227
+ /** Mark a wallet request as being processed */
228
+ startWalletRequest: (id: string) => void;
229
+ /** Complete a wallet request — dequeues + sends response to backend */
230
+ resolveWalletRequest: (id: string, result: WalletRequestResult) => void;
231
+ /** Fail a wallet request — dequeues + sends error to backend */
232
+ rejectWalletRequest: (id: string, error?: string) => void;
293
233
  /** Subscribe to inbound events by type. Returns unsubscribe function. */
294
234
  subscribe: (type: string, callback: EventSubscriber) => () => void;
295
235
  /** Send a system command to the backend */
296
- sendSystemCommand: (event: Omit<OutboundEvent, "timestamp">) => void;
236
+ sendSystemCommand: (event: Omit<OutboundEvent, "timestamp">) => Promise<void>;
297
237
  /** Current SSE connection status */
298
238
  sseStatus: SSEStatus;
299
239
  };
@@ -331,48 +271,19 @@ type EventContext = {
331
271
  /** Subscribe to inbound events by type. Returns unsubscribe function. */
332
272
  subscribe: (type: string, callback: EventSubscriber) => () => void;
333
273
  /** Send an outbound event to backend immediately */
334
- sendOutboundSystem: (event: Omit<OutboundEvent, "timestamp">) => void;
274
+ sendOutboundSystem: (event: Omit<OutboundEvent, "timestamp">) => Promise<void>;
335
275
  /** Dispatch system events from HTTP polling into the event buffer */
336
- dispatchInboundSystem: (sessionId: string, events: ApiSystemEvent[]) => void;
276
+ dispatchInboundSystem: (sessionId: string, events: AomiSystemEvent[]) => void;
337
277
  /** Current SSE connection status */
338
278
  sseStatus: SSEStatus;
339
279
  };
340
280
  declare function useEventContext(): EventContext;
341
281
  type EventContextProviderProps = {
342
282
  children: ReactNode;
343
- backendApi: BackendApi;
283
+ aomiClient: AomiClient;
344
284
  sessionId: string;
345
285
  };
346
- declare function EventContextProvider({ children, backendApi, sessionId, }: EventContextProviderProps): react_jsx_runtime.JSX.Element;
347
-
348
- type WalletTxRequest = {
349
- to: string;
350
- value?: string;
351
- data?: string;
352
- chainId?: number;
353
- };
354
- type WalletTxComplete = {
355
- txHash: string;
356
- status: "success" | "failed";
357
- amount?: string;
358
- token?: string;
359
- };
360
- type WalletConnectionStatus = "connected" | "disconnected";
361
- type WalletHandlerConfig = {
362
- sessionId: string;
363
- onTxRequest?: (request: WalletTxRequest) => void;
364
- };
365
- type WalletHanderApi = {
366
- /** Send transaction completion event to backend */
367
- sendTxComplete: (tx: WalletTxComplete) => void;
368
- /** Send wallet connection status change and update user state */
369
- sendConnectionChange: (status: WalletConnectionStatus, address?: string, chainId?: number) => void;
370
- /** Pending transaction requests from AI */
371
- pendingTxRequests: WalletTxRequest[];
372
- /** Clear a pending request after handling */
373
- clearTxRequest: (index: number) => void;
374
- };
375
- declare function useWalletHandler({ sessionId, onTxRequest, }: WalletHandlerConfig): WalletHanderApi;
286
+ declare function EventContextProvider({ children, aomiClient, sessionId, }: EventContextProviderProps): react_jsx_runtime.JSX.Element;
376
287
 
377
288
  type Notification = {
378
289
  id: string;
@@ -429,28 +340,28 @@ type ControlState = {
429
340
  apiKey: string | null;
430
341
  /** Available models fetched from backend */
431
342
  availableModels: string[];
432
- /** Authorized namespaces fetched from backend */
433
- authorizedNamespaces: string[];
343
+ /** Authorized apps fetched from backend */
344
+ authorizedApps: string[];
434
345
  /** Default model (first from availableModels) */
435
346
  defaultModel: string | null;
436
- /** Default namespace (from authorizedNamespaces) */
437
- defaultNamespace: string | null;
347
+ /** Default app (from authorizedApps) */
348
+ defaultApp: string | null;
438
349
  };
439
350
  type ControlContextApi = {
440
- /** Global state (apiKey, available models/namespaces) */
351
+ /** Global state (apiKey, available models/apps) */
441
352
  state: ControlState;
442
353
  /** Update global state (apiKey only) */
443
354
  setApiKey: (apiKey: string | null) => void;
444
355
  /** Fetch available models from backend */
445
356
  getAvailableModels: () => Promise<string[]>;
446
- /** Fetch authorized namespaces from backend */
447
- getAuthorizedNamespaces: () => Promise<string[]>;
357
+ /** Fetch authorized apps from backend */
358
+ getAuthorizedApps: () => Promise<string[]>;
448
359
  /** Get current thread's control state */
449
360
  getCurrentThreadControl: () => ThreadControlState;
450
361
  /** Select a model for the current thread (updates metadata + calls backend) */
451
362
  onModelSelect: (model: string) => Promise<void>;
452
- /** Select a namespace for the current thread (updates metadata only) */
453
- onNamespaceSelect: (namespace: string) => void;
363
+ /** Select an app for the current thread (updates metadata only) */
364
+ onAppSelect: (app: string) => void;
454
365
  /** Whether the current thread is processing (disables control switching) */
455
366
  isProcessing: boolean;
456
367
  /** Mark control state as synced (called after chat starts) */
@@ -459,16 +370,16 @@ type ControlContextApi = {
459
370
  getControlState: () => ControlState;
460
371
  /** Subscribe to global state changes */
461
372
  onControlStateChange: (callback: (state: ControlState) => void) => () => void;
462
- /** @deprecated Use getCurrentThreadControl().namespace instead */
373
+ /** @deprecated Use getCurrentThreadControl().app instead */
463
374
  setState: (updates: Partial<{
464
- namespace: string | null;
375
+ app: string | null;
465
376
  apiKey: string | null;
466
377
  }>) => void;
467
378
  };
468
379
  declare function useControl(): ControlContextApi;
469
380
  type ControlContextProviderProps = {
470
381
  children: ReactNode;
471
- backendApi: BackendApi;
382
+ aomiClient: AomiClient;
472
383
  sessionId: string;
473
384
  publicKey?: string;
474
385
  /** Get metadata for a thread */
@@ -476,6 +387,6 @@ type ControlContextProviderProps = {
476
387
  /** Update metadata for a thread */
477
388
  updateThreadMetadata: (threadId: string, updates: Partial<ThreadMetadata>) => void;
478
389
  };
479
- declare function ControlContextProvider({ children, backendApi, sessionId, publicKey, getThreadMetadata, updateThreadMetadata, }: ControlContextProviderProps): react_jsx_runtime.JSX.Element;
390
+ declare function ControlContextProvider({ children, aomiClient, sessionId, publicKey, getThreadMetadata, updateThreadMetadata, }: ControlContextProviderProps): react_jsx_runtime.JSX.Element;
480
391
 
481
- 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 ChainInfo, type ControlContextApi, ControlContextProvider, type ControlContextProviderProps, type ControlState, 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, SUPPORTED_CHAINS, type NotificationData as ShowNotificationParams, type ThreadContext, ThreadContextProvider, type ThreadControlState, type ThreadMetadata, type UserConfig, UserContextProvider, type UserState, type UserState as WalletButtonState, type WalletConnectionStatus, type WalletHanderApi, type WalletHandlerConfig, type WalletTxComplete, type WalletTxRequest, cn, formatAddress, getChainInfo, getNetworkName, initThreadControl, useAomiRuntime, useControl, useCurrentThreadMessages, useCurrentThreadMetadata, useEventContext, useNotification, useNotificationHandler, useThreadContext, useUser, useWalletHandler };
392
+ 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 WalletEip712Payload, type WalletHandlerApi, type WalletHandlerConfig, type WalletRequest, type WalletRequestKind, type WalletRequestResult, type WalletRequestStatus, type WalletTxPayload, cn, formatAddress, getChainInfo, getNetworkName, initThreadControl, useAomiRuntime, useControl, useCurrentThreadMessages, useCurrentThreadMetadata, useEventContext, useNotification, useNotificationHandler, useThreadContext, useUser, useWalletHandler };