@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/README.md +142 -0
- package/dist/index.cjs +415 -944
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +94 -183
- package/dist/index.d.ts +94 -183
- package/dist/index.js +410 -932
- package/dist/index.js.map +1 -1
- package/package.json +5 -3
package/dist/index.d.ts
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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"
|
|
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
|
|
185
|
-
|
|
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,
|
|
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:
|
|
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
|
-
|
|
283
|
+
aomiClient: AomiClient;
|
|
344
284
|
sessionId: string;
|
|
345
285
|
};
|
|
346
|
-
declare function EventContextProvider({ children,
|
|
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
|
|
433
|
-
|
|
343
|
+
/** Authorized apps fetched from backend */
|
|
344
|
+
authorizedApps: string[];
|
|
434
345
|
/** Default model (first from availableModels) */
|
|
435
346
|
defaultModel: string | null;
|
|
436
|
-
/** Default
|
|
437
|
-
|
|
347
|
+
/** Default app (from authorizedApps) */
|
|
348
|
+
defaultApp: string | null;
|
|
438
349
|
};
|
|
439
350
|
type ControlContextApi = {
|
|
440
|
-
/** Global state (apiKey, available models/
|
|
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
|
|
447
|
-
|
|
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
|
|
453
|
-
|
|
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().
|
|
373
|
+
/** @deprecated Use getCurrentThreadControl().app instead */
|
|
463
374
|
setState: (updates: Partial<{
|
|
464
|
-
|
|
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
|
-
|
|
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,
|
|
390
|
+
declare function ControlContextProvider({ children, aomiClient, sessionId, publicKey, getThreadMetadata, updateThreadMetadata, }: ControlContextProviderProps): react_jsx_runtime.JSX.Element;
|
|
480
391
|
|
|
481
|
-
export { type
|
|
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 };
|