@aomi-labs/client 0.1.0
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 +515 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +212 -0
- package/dist/index.d.ts +212 -0
- package/dist/index.js +484 -0
- package/dist/index.js.map +1 -0
- package/package.json +28 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client-side user state synced with the backend.
|
|
3
|
+
* Typically wallet connection info, but can be any key-value data.
|
|
4
|
+
*/
|
|
5
|
+
type UserState = Record<string, unknown>;
|
|
6
|
+
/**
|
|
7
|
+
* Optional logger for debug output. Pass `console` or any compatible object.
|
|
8
|
+
*/
|
|
9
|
+
type Logger = {
|
|
10
|
+
debug: (...args: unknown[]) => void;
|
|
11
|
+
};
|
|
12
|
+
type AomiClientOptions = {
|
|
13
|
+
/** Base URL of the Aomi backend (e.g. "https://aomi.dev") */
|
|
14
|
+
baseUrl: string;
|
|
15
|
+
/** Default API key for non-default namespaces */
|
|
16
|
+
apiKey?: string;
|
|
17
|
+
/** Optional logger for debug output (default: silent) */
|
|
18
|
+
logger?: Logger;
|
|
19
|
+
};
|
|
20
|
+
interface AomiMessage {
|
|
21
|
+
sender?: "user" | "agent" | "system" | string;
|
|
22
|
+
content?: string;
|
|
23
|
+
timestamp?: string;
|
|
24
|
+
is_streaming?: boolean;
|
|
25
|
+
tool_result?: [string, string] | null;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* GET /api/state
|
|
29
|
+
* Fetches current session state including messages and processing status
|
|
30
|
+
*/
|
|
31
|
+
interface ApiStateResponse {
|
|
32
|
+
messages?: AomiMessage[] | null;
|
|
33
|
+
system_events?: ApiSystemEvent[] | null;
|
|
34
|
+
title?: string | null;
|
|
35
|
+
is_processing?: boolean;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* POST /api/chat
|
|
39
|
+
* Sends a chat message and returns updated session state
|
|
40
|
+
*/
|
|
41
|
+
interface ApiChatResponse {
|
|
42
|
+
messages?: AomiMessage[] | null;
|
|
43
|
+
system_events?: ApiSystemEvent[] | null;
|
|
44
|
+
title?: string | null;
|
|
45
|
+
is_processing?: boolean;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* POST /api/system
|
|
49
|
+
* Sends a system message and returns the response message
|
|
50
|
+
*/
|
|
51
|
+
interface ApiSystemResponse {
|
|
52
|
+
res?: AomiMessage | null;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* POST /api/interrupt
|
|
56
|
+
* Interrupts current processing and returns updated session state
|
|
57
|
+
*/
|
|
58
|
+
type ApiInterruptResponse = ApiChatResponse;
|
|
59
|
+
/**
|
|
60
|
+
* GET /api/sessions
|
|
61
|
+
* Returns array of ApiThread
|
|
62
|
+
*/
|
|
63
|
+
interface ApiThread {
|
|
64
|
+
session_id: string;
|
|
65
|
+
title: string;
|
|
66
|
+
is_archived?: boolean;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* POST /api/sessions
|
|
70
|
+
* Creates a new thread/session
|
|
71
|
+
*/
|
|
72
|
+
interface ApiCreateThreadResponse {
|
|
73
|
+
session_id: string;
|
|
74
|
+
title?: string;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Base SSE event - all events have session_id and type
|
|
78
|
+
*/
|
|
79
|
+
type ApiSSEEvent = {
|
|
80
|
+
type: "title_changed" | "tool_update" | "tool_complete" | "system_notice" | string;
|
|
81
|
+
session_id: string;
|
|
82
|
+
new_title?: string;
|
|
83
|
+
[key: string]: unknown;
|
|
84
|
+
};
|
|
85
|
+
type ApiSSEEventType = "title_changed" | "tool_update" | "tool_complete" | "system_notice";
|
|
86
|
+
/**
|
|
87
|
+
* Backend SystemEvent enum serializes as tagged JSON:
|
|
88
|
+
* - InlineCall: {"InlineCall": {"type": "wallet_tx_request", "payload": {...}}}
|
|
89
|
+
* - SystemNotice: {"SystemNotice": "message"}
|
|
90
|
+
* - SystemError: {"SystemError": "message"}
|
|
91
|
+
* - AsyncCallback: {"AsyncCallback": {...}} (not sent over HTTP)
|
|
92
|
+
*/
|
|
93
|
+
type ApiSystemEvent = {
|
|
94
|
+
InlineCall: {
|
|
95
|
+
type: string;
|
|
96
|
+
payload?: unknown;
|
|
97
|
+
[key: string]: unknown;
|
|
98
|
+
};
|
|
99
|
+
} | {
|
|
100
|
+
SystemNotice: string;
|
|
101
|
+
} | {
|
|
102
|
+
SystemError: string;
|
|
103
|
+
} | {
|
|
104
|
+
AsyncCallback: Record<string, unknown>;
|
|
105
|
+
};
|
|
106
|
+
declare function isInlineCall(event: ApiSystemEvent): event is {
|
|
107
|
+
InlineCall: {
|
|
108
|
+
type: string;
|
|
109
|
+
payload?: unknown;
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
declare function isSystemNotice(event: ApiSystemEvent): event is {
|
|
113
|
+
SystemNotice: string;
|
|
114
|
+
};
|
|
115
|
+
declare function isSystemError(event: ApiSystemEvent): event is {
|
|
116
|
+
SystemError: string;
|
|
117
|
+
};
|
|
118
|
+
declare function isAsyncCallback(event: ApiSystemEvent): event is {
|
|
119
|
+
AsyncCallback: Record<string, unknown>;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
declare class AomiClient {
|
|
123
|
+
private readonly baseUrl;
|
|
124
|
+
private readonly apiKey?;
|
|
125
|
+
private readonly logger?;
|
|
126
|
+
private readonly sseSubscriber;
|
|
127
|
+
constructor(options: AomiClientOptions);
|
|
128
|
+
/**
|
|
129
|
+
* Fetch current session state (messages, processing status, title).
|
|
130
|
+
*/
|
|
131
|
+
fetchState(sessionId: string, userState?: UserState): Promise<ApiStateResponse>;
|
|
132
|
+
/**
|
|
133
|
+
* Send a chat message and return updated session state.
|
|
134
|
+
*/
|
|
135
|
+
sendMessage(sessionId: string, message: string, options?: {
|
|
136
|
+
namespace?: string;
|
|
137
|
+
publicKey?: string;
|
|
138
|
+
apiKey?: string;
|
|
139
|
+
userState?: UserState;
|
|
140
|
+
}): Promise<ApiChatResponse>;
|
|
141
|
+
/**
|
|
142
|
+
* Send a system-level message (e.g. wallet state changes, context switches).
|
|
143
|
+
*/
|
|
144
|
+
sendSystemMessage(sessionId: string, message: string): Promise<ApiSystemResponse>;
|
|
145
|
+
/**
|
|
146
|
+
* Interrupt the AI's current response.
|
|
147
|
+
*/
|
|
148
|
+
interrupt(sessionId: string): Promise<ApiInterruptResponse>;
|
|
149
|
+
/**
|
|
150
|
+
* Subscribe to real-time SSE updates for a session.
|
|
151
|
+
* Automatically reconnects with exponential backoff on disconnects.
|
|
152
|
+
* Returns an unsubscribe function.
|
|
153
|
+
*/
|
|
154
|
+
subscribeSSE(sessionId: string, onUpdate: (event: ApiSSEEvent) => void, onError?: (error: unknown) => void): () => void;
|
|
155
|
+
/**
|
|
156
|
+
* List all threads for a wallet address.
|
|
157
|
+
*/
|
|
158
|
+
listThreads(publicKey: string): Promise<ApiThread[]>;
|
|
159
|
+
/**
|
|
160
|
+
* Get a single thread by ID.
|
|
161
|
+
*/
|
|
162
|
+
getThread(sessionId: string): Promise<ApiThread>;
|
|
163
|
+
/**
|
|
164
|
+
* Create a new thread. The client generates the session ID.
|
|
165
|
+
*/
|
|
166
|
+
createThread(threadId: string, publicKey?: string): Promise<ApiCreateThreadResponse>;
|
|
167
|
+
/**
|
|
168
|
+
* Delete a thread by ID.
|
|
169
|
+
*/
|
|
170
|
+
deleteThread(sessionId: string): Promise<void>;
|
|
171
|
+
/**
|
|
172
|
+
* Rename a thread.
|
|
173
|
+
*/
|
|
174
|
+
renameThread(sessionId: string, newTitle: string): Promise<void>;
|
|
175
|
+
/**
|
|
176
|
+
* Archive a thread.
|
|
177
|
+
*/
|
|
178
|
+
archiveThread(sessionId: string): Promise<void>;
|
|
179
|
+
/**
|
|
180
|
+
* Unarchive a thread.
|
|
181
|
+
*/
|
|
182
|
+
unarchiveThread(sessionId: string): Promise<void>;
|
|
183
|
+
/**
|
|
184
|
+
* Get system events for a session.
|
|
185
|
+
*/
|
|
186
|
+
getSystemEvents(sessionId: string, count?: number): Promise<ApiSystemEvent[]>;
|
|
187
|
+
/**
|
|
188
|
+
* Get available namespaces.
|
|
189
|
+
*/
|
|
190
|
+
getNamespaces(sessionId: string, options?: {
|
|
191
|
+
publicKey?: string;
|
|
192
|
+
apiKey?: string;
|
|
193
|
+
}): Promise<string[]>;
|
|
194
|
+
/**
|
|
195
|
+
* Get available models.
|
|
196
|
+
*/
|
|
197
|
+
getModels(sessionId: string): Promise<string[]>;
|
|
198
|
+
/**
|
|
199
|
+
* Set the model for a session.
|
|
200
|
+
*/
|
|
201
|
+
setModel(sessionId: string, rig: string, options?: {
|
|
202
|
+
namespace?: string;
|
|
203
|
+
apiKey?: string;
|
|
204
|
+
}): Promise<{
|
|
205
|
+
success: boolean;
|
|
206
|
+
rig: string;
|
|
207
|
+
baml: string;
|
|
208
|
+
created: boolean;
|
|
209
|
+
}>;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
export { AomiClient, type AomiClientOptions, type AomiMessage, type ApiChatResponse, type ApiCreateThreadResponse, type ApiInterruptResponse, type ApiSSEEvent, type ApiSSEEventType, type ApiStateResponse, type ApiSystemEvent, type ApiSystemResponse, type ApiThread, type Logger, type UserState, isAsyncCallback, isInlineCall, isSystemError, isSystemNotice };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client-side user state synced with the backend.
|
|
3
|
+
* Typically wallet connection info, but can be any key-value data.
|
|
4
|
+
*/
|
|
5
|
+
type UserState = Record<string, unknown>;
|
|
6
|
+
/**
|
|
7
|
+
* Optional logger for debug output. Pass `console` or any compatible object.
|
|
8
|
+
*/
|
|
9
|
+
type Logger = {
|
|
10
|
+
debug: (...args: unknown[]) => void;
|
|
11
|
+
};
|
|
12
|
+
type AomiClientOptions = {
|
|
13
|
+
/** Base URL of the Aomi backend (e.g. "https://aomi.dev") */
|
|
14
|
+
baseUrl: string;
|
|
15
|
+
/** Default API key for non-default namespaces */
|
|
16
|
+
apiKey?: string;
|
|
17
|
+
/** Optional logger for debug output (default: silent) */
|
|
18
|
+
logger?: Logger;
|
|
19
|
+
};
|
|
20
|
+
interface AomiMessage {
|
|
21
|
+
sender?: "user" | "agent" | "system" | string;
|
|
22
|
+
content?: string;
|
|
23
|
+
timestamp?: string;
|
|
24
|
+
is_streaming?: boolean;
|
|
25
|
+
tool_result?: [string, string] | null;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* GET /api/state
|
|
29
|
+
* Fetches current session state including messages and processing status
|
|
30
|
+
*/
|
|
31
|
+
interface ApiStateResponse {
|
|
32
|
+
messages?: AomiMessage[] | null;
|
|
33
|
+
system_events?: ApiSystemEvent[] | null;
|
|
34
|
+
title?: string | null;
|
|
35
|
+
is_processing?: boolean;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* POST /api/chat
|
|
39
|
+
* Sends a chat message and returns updated session state
|
|
40
|
+
*/
|
|
41
|
+
interface ApiChatResponse {
|
|
42
|
+
messages?: AomiMessage[] | null;
|
|
43
|
+
system_events?: ApiSystemEvent[] | null;
|
|
44
|
+
title?: string | null;
|
|
45
|
+
is_processing?: boolean;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* POST /api/system
|
|
49
|
+
* Sends a system message and returns the response message
|
|
50
|
+
*/
|
|
51
|
+
interface ApiSystemResponse {
|
|
52
|
+
res?: AomiMessage | null;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* POST /api/interrupt
|
|
56
|
+
* Interrupts current processing and returns updated session state
|
|
57
|
+
*/
|
|
58
|
+
type ApiInterruptResponse = ApiChatResponse;
|
|
59
|
+
/**
|
|
60
|
+
* GET /api/sessions
|
|
61
|
+
* Returns array of ApiThread
|
|
62
|
+
*/
|
|
63
|
+
interface ApiThread {
|
|
64
|
+
session_id: string;
|
|
65
|
+
title: string;
|
|
66
|
+
is_archived?: boolean;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* POST /api/sessions
|
|
70
|
+
* Creates a new thread/session
|
|
71
|
+
*/
|
|
72
|
+
interface ApiCreateThreadResponse {
|
|
73
|
+
session_id: string;
|
|
74
|
+
title?: string;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Base SSE event - all events have session_id and type
|
|
78
|
+
*/
|
|
79
|
+
type ApiSSEEvent = {
|
|
80
|
+
type: "title_changed" | "tool_update" | "tool_complete" | "system_notice" | string;
|
|
81
|
+
session_id: string;
|
|
82
|
+
new_title?: string;
|
|
83
|
+
[key: string]: unknown;
|
|
84
|
+
};
|
|
85
|
+
type ApiSSEEventType = "title_changed" | "tool_update" | "tool_complete" | "system_notice";
|
|
86
|
+
/**
|
|
87
|
+
* Backend SystemEvent enum serializes as tagged JSON:
|
|
88
|
+
* - InlineCall: {"InlineCall": {"type": "wallet_tx_request", "payload": {...}}}
|
|
89
|
+
* - SystemNotice: {"SystemNotice": "message"}
|
|
90
|
+
* - SystemError: {"SystemError": "message"}
|
|
91
|
+
* - AsyncCallback: {"AsyncCallback": {...}} (not sent over HTTP)
|
|
92
|
+
*/
|
|
93
|
+
type ApiSystemEvent = {
|
|
94
|
+
InlineCall: {
|
|
95
|
+
type: string;
|
|
96
|
+
payload?: unknown;
|
|
97
|
+
[key: string]: unknown;
|
|
98
|
+
};
|
|
99
|
+
} | {
|
|
100
|
+
SystemNotice: string;
|
|
101
|
+
} | {
|
|
102
|
+
SystemError: string;
|
|
103
|
+
} | {
|
|
104
|
+
AsyncCallback: Record<string, unknown>;
|
|
105
|
+
};
|
|
106
|
+
declare function isInlineCall(event: ApiSystemEvent): event is {
|
|
107
|
+
InlineCall: {
|
|
108
|
+
type: string;
|
|
109
|
+
payload?: unknown;
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
declare function isSystemNotice(event: ApiSystemEvent): event is {
|
|
113
|
+
SystemNotice: string;
|
|
114
|
+
};
|
|
115
|
+
declare function isSystemError(event: ApiSystemEvent): event is {
|
|
116
|
+
SystemError: string;
|
|
117
|
+
};
|
|
118
|
+
declare function isAsyncCallback(event: ApiSystemEvent): event is {
|
|
119
|
+
AsyncCallback: Record<string, unknown>;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
declare class AomiClient {
|
|
123
|
+
private readonly baseUrl;
|
|
124
|
+
private readonly apiKey?;
|
|
125
|
+
private readonly logger?;
|
|
126
|
+
private readonly sseSubscriber;
|
|
127
|
+
constructor(options: AomiClientOptions);
|
|
128
|
+
/**
|
|
129
|
+
* Fetch current session state (messages, processing status, title).
|
|
130
|
+
*/
|
|
131
|
+
fetchState(sessionId: string, userState?: UserState): Promise<ApiStateResponse>;
|
|
132
|
+
/**
|
|
133
|
+
* Send a chat message and return updated session state.
|
|
134
|
+
*/
|
|
135
|
+
sendMessage(sessionId: string, message: string, options?: {
|
|
136
|
+
namespace?: string;
|
|
137
|
+
publicKey?: string;
|
|
138
|
+
apiKey?: string;
|
|
139
|
+
userState?: UserState;
|
|
140
|
+
}): Promise<ApiChatResponse>;
|
|
141
|
+
/**
|
|
142
|
+
* Send a system-level message (e.g. wallet state changes, context switches).
|
|
143
|
+
*/
|
|
144
|
+
sendSystemMessage(sessionId: string, message: string): Promise<ApiSystemResponse>;
|
|
145
|
+
/**
|
|
146
|
+
* Interrupt the AI's current response.
|
|
147
|
+
*/
|
|
148
|
+
interrupt(sessionId: string): Promise<ApiInterruptResponse>;
|
|
149
|
+
/**
|
|
150
|
+
* Subscribe to real-time SSE updates for a session.
|
|
151
|
+
* Automatically reconnects with exponential backoff on disconnects.
|
|
152
|
+
* Returns an unsubscribe function.
|
|
153
|
+
*/
|
|
154
|
+
subscribeSSE(sessionId: string, onUpdate: (event: ApiSSEEvent) => void, onError?: (error: unknown) => void): () => void;
|
|
155
|
+
/**
|
|
156
|
+
* List all threads for a wallet address.
|
|
157
|
+
*/
|
|
158
|
+
listThreads(publicKey: string): Promise<ApiThread[]>;
|
|
159
|
+
/**
|
|
160
|
+
* Get a single thread by ID.
|
|
161
|
+
*/
|
|
162
|
+
getThread(sessionId: string): Promise<ApiThread>;
|
|
163
|
+
/**
|
|
164
|
+
* Create a new thread. The client generates the session ID.
|
|
165
|
+
*/
|
|
166
|
+
createThread(threadId: string, publicKey?: string): Promise<ApiCreateThreadResponse>;
|
|
167
|
+
/**
|
|
168
|
+
* Delete a thread by ID.
|
|
169
|
+
*/
|
|
170
|
+
deleteThread(sessionId: string): Promise<void>;
|
|
171
|
+
/**
|
|
172
|
+
* Rename a thread.
|
|
173
|
+
*/
|
|
174
|
+
renameThread(sessionId: string, newTitle: string): Promise<void>;
|
|
175
|
+
/**
|
|
176
|
+
* Archive a thread.
|
|
177
|
+
*/
|
|
178
|
+
archiveThread(sessionId: string): Promise<void>;
|
|
179
|
+
/**
|
|
180
|
+
* Unarchive a thread.
|
|
181
|
+
*/
|
|
182
|
+
unarchiveThread(sessionId: string): Promise<void>;
|
|
183
|
+
/**
|
|
184
|
+
* Get system events for a session.
|
|
185
|
+
*/
|
|
186
|
+
getSystemEvents(sessionId: string, count?: number): Promise<ApiSystemEvent[]>;
|
|
187
|
+
/**
|
|
188
|
+
* Get available namespaces.
|
|
189
|
+
*/
|
|
190
|
+
getNamespaces(sessionId: string, options?: {
|
|
191
|
+
publicKey?: string;
|
|
192
|
+
apiKey?: string;
|
|
193
|
+
}): Promise<string[]>;
|
|
194
|
+
/**
|
|
195
|
+
* Get available models.
|
|
196
|
+
*/
|
|
197
|
+
getModels(sessionId: string): Promise<string[]>;
|
|
198
|
+
/**
|
|
199
|
+
* Set the model for a session.
|
|
200
|
+
*/
|
|
201
|
+
setModel(sessionId: string, rig: string, options?: {
|
|
202
|
+
namespace?: string;
|
|
203
|
+
apiKey?: string;
|
|
204
|
+
}): Promise<{
|
|
205
|
+
success: boolean;
|
|
206
|
+
rig: string;
|
|
207
|
+
baml: string;
|
|
208
|
+
created: boolean;
|
|
209
|
+
}>;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
export { AomiClient, type AomiClientOptions, type AomiMessage, type ApiChatResponse, type ApiCreateThreadResponse, type ApiInterruptResponse, type ApiSSEEvent, type ApiSSEEventType, type ApiStateResponse, type ApiSystemEvent, type ApiSystemResponse, type ApiThread, type Logger, type UserState, isAsyncCallback, isInlineCall, isSystemError, isSystemNotice };
|