@aomi-labs/client 0.1.2 → 0.1.5
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 +3 -1
- package/dist/cli.js +240 -103
- package/dist/index.cjs +76 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +16 -10
- package/dist/index.d.ts +16 -10
- package/dist/index.js +76 -13
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/skills/aomi-transact/SKILL.md +13 -6
package/dist/index.d.cts
CHANGED
|
@@ -12,7 +12,7 @@ type Logger = {
|
|
|
12
12
|
type AomiClientOptions = {
|
|
13
13
|
/** Base URL of the Aomi backend (e.g. "https://aomi.dev") */
|
|
14
14
|
baseUrl: string;
|
|
15
|
-
/** Default API key for non-default
|
|
15
|
+
/** Default API key for non-default apps */
|
|
16
16
|
apiKey?: string;
|
|
17
17
|
/** Optional logger for debug output (default: silent) */
|
|
18
18
|
logger?: Logger;
|
|
@@ -33,6 +33,7 @@ interface AomiStateResponse {
|
|
|
33
33
|
system_events?: AomiSystemEvent[] | null;
|
|
34
34
|
title?: string | null;
|
|
35
35
|
is_processing?: boolean;
|
|
36
|
+
user_state?: UserState | null;
|
|
36
37
|
}
|
|
37
38
|
/**
|
|
38
39
|
* POST /api/chat
|
|
@@ -43,6 +44,7 @@ interface AomiChatResponse {
|
|
|
43
44
|
system_events?: AomiSystemEvent[] | null;
|
|
44
45
|
title?: string | null;
|
|
45
46
|
is_processing?: boolean;
|
|
47
|
+
user_state?: UserState | null;
|
|
46
48
|
}
|
|
47
49
|
/**
|
|
48
50
|
* POST /api/system
|
|
@@ -133,7 +135,7 @@ declare class AomiClient {
|
|
|
133
135
|
* Send a chat message and return updated session state.
|
|
134
136
|
*/
|
|
135
137
|
sendMessage(sessionId: string, message: string, options?: {
|
|
136
|
-
|
|
138
|
+
app?: string;
|
|
137
139
|
publicKey?: string;
|
|
138
140
|
apiKey?: string;
|
|
139
141
|
userState?: UserState;
|
|
@@ -185,9 +187,9 @@ declare class AomiClient {
|
|
|
185
187
|
*/
|
|
186
188
|
getSystemEvents(sessionId: string, count?: number): Promise<AomiSystemEvent[]>;
|
|
187
189
|
/**
|
|
188
|
-
* Get available
|
|
190
|
+
* Get available apps.
|
|
189
191
|
*/
|
|
190
|
-
|
|
192
|
+
getApps(sessionId: string, options?: {
|
|
191
193
|
publicKey?: string;
|
|
192
194
|
apiKey?: string;
|
|
193
195
|
}): Promise<string[]>;
|
|
@@ -201,7 +203,7 @@ declare class AomiClient {
|
|
|
201
203
|
* Set the model for a session.
|
|
202
204
|
*/
|
|
203
205
|
setModel(sessionId: string, rig: string, options?: {
|
|
204
|
-
|
|
206
|
+
app?: string;
|
|
205
207
|
apiKey?: string;
|
|
206
208
|
}): Promise<{
|
|
207
209
|
success: boolean;
|
|
@@ -295,8 +297,8 @@ type SendResult = {
|
|
|
295
297
|
type SessionOptions = {
|
|
296
298
|
/** Session ID. Auto-generated (crypto.randomUUID) if omitted. */
|
|
297
299
|
sessionId?: string;
|
|
298
|
-
/**
|
|
299
|
-
|
|
300
|
+
/** App for chat messages. Default: "default" */
|
|
301
|
+
app?: string;
|
|
300
302
|
/** User public key (wallet address). */
|
|
301
303
|
publicKey?: string;
|
|
302
304
|
/** API key override. */
|
|
@@ -350,12 +352,12 @@ type SessionEventMap = {
|
|
|
350
352
|
payload: unknown;
|
|
351
353
|
};
|
|
352
354
|
};
|
|
353
|
-
declare class
|
|
355
|
+
declare class ClientSession extends TypedEventEmitter<SessionEventMap> {
|
|
354
356
|
/** The underlying low-level client. */
|
|
355
357
|
readonly client: AomiClient;
|
|
356
358
|
/** The session (thread) ID. */
|
|
357
359
|
readonly sessionId: string;
|
|
358
|
-
private
|
|
360
|
+
private app;
|
|
359
361
|
private publicKey?;
|
|
360
362
|
private apiKey?;
|
|
361
363
|
private userState?;
|
|
@@ -412,6 +414,9 @@ declare class Session extends TypedEventEmitter<SessionEventMap> {
|
|
|
412
414
|
getPendingRequests(): WalletRequest[];
|
|
413
415
|
/** Whether the AI is currently processing. */
|
|
414
416
|
getIsProcessing(): boolean;
|
|
417
|
+
resolveUserState(userState: UserState): void;
|
|
418
|
+
resolveWallet(address: string, chainId?: number): void;
|
|
419
|
+
syncUserState(): Promise<AomiStateResponse>;
|
|
415
420
|
private startPolling;
|
|
416
421
|
private stopPolling;
|
|
417
422
|
private pollTick;
|
|
@@ -423,6 +428,7 @@ declare class Session extends TypedEventEmitter<SessionEventMap> {
|
|
|
423
428
|
private sendSystemEvent;
|
|
424
429
|
private resolvePending;
|
|
425
430
|
private assertOpen;
|
|
431
|
+
private assertUserStateAligned;
|
|
426
432
|
}
|
|
427
433
|
|
|
428
434
|
type UnwrappedEvent = {
|
|
@@ -440,4 +446,4 @@ type UnwrappedEvent = {
|
|
|
440
446
|
*/
|
|
441
447
|
declare function unwrapSystemEvent(event: AomiSystemEvent): UnwrappedEvent | null;
|
|
442
448
|
|
|
443
|
-
export { type AomiChatResponse, AomiClient, type AomiClientOptions, type AomiCreateThreadResponse, type AomiInterruptResponse, type AomiMessage, type AomiSSEEvent, type AomiSSEEventType, type AomiStateResponse, type AomiSystemEvent, type AomiSystemResponse, type AomiThread, type Logger, type SendResult, Session, type SessionEventMap, type SessionOptions, TypedEventEmitter, type UnwrappedEvent, type UserState, type WalletEip712Payload, type WalletRequest, type WalletRequestKind, type WalletRequestResult, type WalletTxPayload, isAsyncCallback, isInlineCall, isSystemError, isSystemNotice, normalizeEip712Payload, normalizeTxPayload, unwrapSystemEvent };
|
|
449
|
+
export { type AomiChatResponse, AomiClient, type AomiClientOptions, type AomiCreateThreadResponse, type AomiInterruptResponse, type AomiMessage, type AomiSSEEvent, type AomiSSEEventType, type AomiStateResponse, type AomiSystemEvent, type AomiSystemResponse, type AomiThread, type Logger, type SendResult, ClientSession as Session, type SessionEventMap, type SessionOptions, TypedEventEmitter, type UnwrappedEvent, type UserState, type WalletEip712Payload, type WalletRequest, type WalletRequestKind, type WalletRequestResult, type WalletTxPayload, isAsyncCallback, isInlineCall, isSystemError, isSystemNotice, normalizeEip712Payload, normalizeTxPayload, unwrapSystemEvent };
|
package/dist/index.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ type Logger = {
|
|
|
12
12
|
type AomiClientOptions = {
|
|
13
13
|
/** Base URL of the Aomi backend (e.g. "https://aomi.dev") */
|
|
14
14
|
baseUrl: string;
|
|
15
|
-
/** Default API key for non-default
|
|
15
|
+
/** Default API key for non-default apps */
|
|
16
16
|
apiKey?: string;
|
|
17
17
|
/** Optional logger for debug output (default: silent) */
|
|
18
18
|
logger?: Logger;
|
|
@@ -33,6 +33,7 @@ interface AomiStateResponse {
|
|
|
33
33
|
system_events?: AomiSystemEvent[] | null;
|
|
34
34
|
title?: string | null;
|
|
35
35
|
is_processing?: boolean;
|
|
36
|
+
user_state?: UserState | null;
|
|
36
37
|
}
|
|
37
38
|
/**
|
|
38
39
|
* POST /api/chat
|
|
@@ -43,6 +44,7 @@ interface AomiChatResponse {
|
|
|
43
44
|
system_events?: AomiSystemEvent[] | null;
|
|
44
45
|
title?: string | null;
|
|
45
46
|
is_processing?: boolean;
|
|
47
|
+
user_state?: UserState | null;
|
|
46
48
|
}
|
|
47
49
|
/**
|
|
48
50
|
* POST /api/system
|
|
@@ -133,7 +135,7 @@ declare class AomiClient {
|
|
|
133
135
|
* Send a chat message and return updated session state.
|
|
134
136
|
*/
|
|
135
137
|
sendMessage(sessionId: string, message: string, options?: {
|
|
136
|
-
|
|
138
|
+
app?: string;
|
|
137
139
|
publicKey?: string;
|
|
138
140
|
apiKey?: string;
|
|
139
141
|
userState?: UserState;
|
|
@@ -185,9 +187,9 @@ declare class AomiClient {
|
|
|
185
187
|
*/
|
|
186
188
|
getSystemEvents(sessionId: string, count?: number): Promise<AomiSystemEvent[]>;
|
|
187
189
|
/**
|
|
188
|
-
* Get available
|
|
190
|
+
* Get available apps.
|
|
189
191
|
*/
|
|
190
|
-
|
|
192
|
+
getApps(sessionId: string, options?: {
|
|
191
193
|
publicKey?: string;
|
|
192
194
|
apiKey?: string;
|
|
193
195
|
}): Promise<string[]>;
|
|
@@ -201,7 +203,7 @@ declare class AomiClient {
|
|
|
201
203
|
* Set the model for a session.
|
|
202
204
|
*/
|
|
203
205
|
setModel(sessionId: string, rig: string, options?: {
|
|
204
|
-
|
|
206
|
+
app?: string;
|
|
205
207
|
apiKey?: string;
|
|
206
208
|
}): Promise<{
|
|
207
209
|
success: boolean;
|
|
@@ -295,8 +297,8 @@ type SendResult = {
|
|
|
295
297
|
type SessionOptions = {
|
|
296
298
|
/** Session ID. Auto-generated (crypto.randomUUID) if omitted. */
|
|
297
299
|
sessionId?: string;
|
|
298
|
-
/**
|
|
299
|
-
|
|
300
|
+
/** App for chat messages. Default: "default" */
|
|
301
|
+
app?: string;
|
|
300
302
|
/** User public key (wallet address). */
|
|
301
303
|
publicKey?: string;
|
|
302
304
|
/** API key override. */
|
|
@@ -350,12 +352,12 @@ type SessionEventMap = {
|
|
|
350
352
|
payload: unknown;
|
|
351
353
|
};
|
|
352
354
|
};
|
|
353
|
-
declare class
|
|
355
|
+
declare class ClientSession extends TypedEventEmitter<SessionEventMap> {
|
|
354
356
|
/** The underlying low-level client. */
|
|
355
357
|
readonly client: AomiClient;
|
|
356
358
|
/** The session (thread) ID. */
|
|
357
359
|
readonly sessionId: string;
|
|
358
|
-
private
|
|
360
|
+
private app;
|
|
359
361
|
private publicKey?;
|
|
360
362
|
private apiKey?;
|
|
361
363
|
private userState?;
|
|
@@ -412,6 +414,9 @@ declare class Session extends TypedEventEmitter<SessionEventMap> {
|
|
|
412
414
|
getPendingRequests(): WalletRequest[];
|
|
413
415
|
/** Whether the AI is currently processing. */
|
|
414
416
|
getIsProcessing(): boolean;
|
|
417
|
+
resolveUserState(userState: UserState): void;
|
|
418
|
+
resolveWallet(address: string, chainId?: number): void;
|
|
419
|
+
syncUserState(): Promise<AomiStateResponse>;
|
|
415
420
|
private startPolling;
|
|
416
421
|
private stopPolling;
|
|
417
422
|
private pollTick;
|
|
@@ -423,6 +428,7 @@ declare class Session extends TypedEventEmitter<SessionEventMap> {
|
|
|
423
428
|
private sendSystemEvent;
|
|
424
429
|
private resolvePending;
|
|
425
430
|
private assertOpen;
|
|
431
|
+
private assertUserStateAligned;
|
|
426
432
|
}
|
|
427
433
|
|
|
428
434
|
type UnwrappedEvent = {
|
|
@@ -440,4 +446,4 @@ type UnwrappedEvent = {
|
|
|
440
446
|
*/
|
|
441
447
|
declare function unwrapSystemEvent(event: AomiSystemEvent): UnwrappedEvent | null;
|
|
442
448
|
|
|
443
|
-
export { type AomiChatResponse, AomiClient, type AomiClientOptions, type AomiCreateThreadResponse, type AomiInterruptResponse, type AomiMessage, type AomiSSEEvent, type AomiSSEEventType, type AomiStateResponse, type AomiSystemEvent, type AomiSystemResponse, type AomiThread, type Logger, type SendResult, Session, type SessionEventMap, type SessionOptions, TypedEventEmitter, type UnwrappedEvent, type UserState, type WalletEip712Payload, type WalletRequest, type WalletRequestKind, type WalletRequestResult, type WalletTxPayload, isAsyncCallback, isInlineCall, isSystemError, isSystemNotice, normalizeEip712Payload, normalizeTxPayload, unwrapSystemEvent };
|
|
449
|
+
export { type AomiChatResponse, AomiClient, type AomiClientOptions, type AomiCreateThreadResponse, type AomiInterruptResponse, type AomiMessage, type AomiSSEEvent, type AomiSSEEventType, type AomiStateResponse, type AomiSystemEvent, type AomiSystemResponse, type AomiThread, type Logger, type SendResult, ClientSession as Session, type SessionEventMap, type SessionOptions, TypedEventEmitter, type UnwrappedEvent, type UserState, type WalletEip712Payload, type WalletRequest, type WalletRequestKind, type WalletRequestResult, type WalletTxPayload, isAsyncCallback, isInlineCall, isSystemError, isSystemNotice, normalizeEip712Payload, normalizeTxPayload, unwrapSystemEvent };
|
package/dist/index.js
CHANGED
|
@@ -240,9 +240,9 @@ var AomiClient = class {
|
|
|
240
240
|
*/
|
|
241
241
|
async sendMessage(sessionId, message, options) {
|
|
242
242
|
var _a, _b;
|
|
243
|
-
const
|
|
243
|
+
const app = (_a = options == null ? void 0 : options.app) != null ? _a : "default";
|
|
244
244
|
const apiKey = (_b = options == null ? void 0 : options.apiKey) != null ? _b : this.apiKey;
|
|
245
|
-
const payload = { message,
|
|
245
|
+
const payload = { message, app };
|
|
246
246
|
if (options == null ? void 0 : options.publicKey) {
|
|
247
247
|
payload.public_key = options.publicKey;
|
|
248
248
|
}
|
|
@@ -415,11 +415,11 @@ var AomiClient = class {
|
|
|
415
415
|
// Control API
|
|
416
416
|
// ===========================================================================
|
|
417
417
|
/**
|
|
418
|
-
* Get available
|
|
418
|
+
* Get available apps.
|
|
419
419
|
*/
|
|
420
|
-
async
|
|
420
|
+
async getApps(sessionId, options) {
|
|
421
421
|
var _a;
|
|
422
|
-
const url = new URL("/api/control/
|
|
422
|
+
const url = new URL("/api/control/apps", this.baseUrl);
|
|
423
423
|
if (options == null ? void 0 : options.publicKey) {
|
|
424
424
|
url.searchParams.set("public_key", options.publicKey);
|
|
425
425
|
}
|
|
@@ -430,7 +430,7 @@ var AomiClient = class {
|
|
|
430
430
|
}
|
|
431
431
|
const response = await fetch(url.toString(), { headers });
|
|
432
432
|
if (!response.ok) {
|
|
433
|
-
throw new Error(`Failed to get
|
|
433
|
+
throw new Error(`Failed to get apps: HTTP ${response.status}`);
|
|
434
434
|
}
|
|
435
435
|
return await response.json();
|
|
436
436
|
}
|
|
@@ -460,8 +460,8 @@ var AomiClient = class {
|
|
|
460
460
|
var _a;
|
|
461
461
|
const apiKey = (_a = options == null ? void 0 : options.apiKey) != null ? _a : this.apiKey;
|
|
462
462
|
const payload = { rig };
|
|
463
|
-
if (options == null ? void 0 : options.
|
|
464
|
-
payload.
|
|
463
|
+
if (options == null ? void 0 : options.app) {
|
|
464
|
+
payload.app = options.app;
|
|
465
465
|
}
|
|
466
466
|
return postState(this.baseUrl, "/api/control/model", payload, sessionId, apiKey);
|
|
467
467
|
}
|
|
@@ -642,7 +642,38 @@ function normalizeEip712Payload(payload) {
|
|
|
642
642
|
}
|
|
643
643
|
|
|
644
644
|
// src/session.ts
|
|
645
|
-
|
|
645
|
+
function sortJson(value) {
|
|
646
|
+
if (Array.isArray(value)) {
|
|
647
|
+
return value.map((entry) => sortJson(entry));
|
|
648
|
+
}
|
|
649
|
+
if (value && typeof value === "object") {
|
|
650
|
+
return Object.keys(value).sort().reduce((acc, key) => {
|
|
651
|
+
acc[key] = sortJson(value[key]);
|
|
652
|
+
return acc;
|
|
653
|
+
}, {});
|
|
654
|
+
}
|
|
655
|
+
return value;
|
|
656
|
+
}
|
|
657
|
+
function isSubsetMatch(expected, actual) {
|
|
658
|
+
if (Array.isArray(expected)) {
|
|
659
|
+
if (!Array.isArray(actual) || expected.length !== actual.length) {
|
|
660
|
+
return false;
|
|
661
|
+
}
|
|
662
|
+
return expected.every(
|
|
663
|
+
(entry, index) => isSubsetMatch(entry, actual[index])
|
|
664
|
+
);
|
|
665
|
+
}
|
|
666
|
+
if (expected && typeof expected === "object") {
|
|
667
|
+
if (!actual || typeof actual !== "object" || Array.isArray(actual)) {
|
|
668
|
+
return false;
|
|
669
|
+
}
|
|
670
|
+
return Object.entries(expected).every(
|
|
671
|
+
([key, value]) => isSubsetMatch(value, actual[key])
|
|
672
|
+
);
|
|
673
|
+
}
|
|
674
|
+
return expected === actual;
|
|
675
|
+
}
|
|
676
|
+
var ClientSession = class extends TypedEventEmitter {
|
|
646
677
|
constructor(clientOrOptions, sessionOptions) {
|
|
647
678
|
var _a, _b, _c;
|
|
648
679
|
super();
|
|
@@ -658,7 +689,7 @@ var Session = class extends TypedEventEmitter {
|
|
|
658
689
|
this.pendingResolve = null;
|
|
659
690
|
this.client = clientOrOptions instanceof AomiClient ? clientOrOptions : new AomiClient(clientOrOptions);
|
|
660
691
|
this.sessionId = (_a = sessionOptions == null ? void 0 : sessionOptions.sessionId) != null ? _a : crypto.randomUUID();
|
|
661
|
-
this.
|
|
692
|
+
this.app = (_b = sessionOptions == null ? void 0 : sessionOptions.app) != null ? _b : "default";
|
|
662
693
|
this.publicKey = sessionOptions == null ? void 0 : sessionOptions.publicKey;
|
|
663
694
|
this.apiKey = sessionOptions == null ? void 0 : sessionOptions.apiKey;
|
|
664
695
|
this.userState = sessionOptions == null ? void 0 : sessionOptions.userState;
|
|
@@ -684,11 +715,12 @@ var Session = class extends TypedEventEmitter {
|
|
|
684
715
|
async send(message) {
|
|
685
716
|
this.assertOpen();
|
|
686
717
|
const response = await this.client.sendMessage(this.sessionId, message, {
|
|
687
|
-
|
|
718
|
+
app: this.app,
|
|
688
719
|
publicKey: this.publicKey,
|
|
689
720
|
apiKey: this.apiKey,
|
|
690
721
|
userState: this.userState
|
|
691
722
|
});
|
|
723
|
+
this.assertUserStateAligned(response.user_state);
|
|
692
724
|
this.applyState(response);
|
|
693
725
|
if (!response.is_processing && this.walletRequests.length === 0) {
|
|
694
726
|
return { messages: this._messages, title: this._title };
|
|
@@ -707,11 +739,12 @@ var Session = class extends TypedEventEmitter {
|
|
|
707
739
|
async sendAsync(message) {
|
|
708
740
|
this.assertOpen();
|
|
709
741
|
const response = await this.client.sendMessage(this.sessionId, message, {
|
|
710
|
-
|
|
742
|
+
app: this.app,
|
|
711
743
|
publicKey: this.publicKey,
|
|
712
744
|
apiKey: this.apiKey,
|
|
713
745
|
userState: this.userState
|
|
714
746
|
});
|
|
747
|
+
this.assertUserStateAligned(response.user_state);
|
|
715
748
|
this.applyState(response);
|
|
716
749
|
if (response.is_processing) {
|
|
717
750
|
this._isProcessing = true;
|
|
@@ -824,6 +857,23 @@ var Session = class extends TypedEventEmitter {
|
|
|
824
857
|
getIsProcessing() {
|
|
825
858
|
return this._isProcessing;
|
|
826
859
|
}
|
|
860
|
+
resolveUserState(userState) {
|
|
861
|
+
this.userState = userState;
|
|
862
|
+
const address = userState["address"];
|
|
863
|
+
if (typeof address === "string" && address.length > 0) {
|
|
864
|
+
this.publicKey = address;
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
resolveWallet(address, chainId) {
|
|
868
|
+
this.resolveUserState({ address, chainId: chainId != null ? chainId : 1, isConnected: true });
|
|
869
|
+
}
|
|
870
|
+
async syncUserState() {
|
|
871
|
+
this.assertOpen();
|
|
872
|
+
const state = await this.client.fetchState(this.sessionId, this.userState);
|
|
873
|
+
this.assertUserStateAligned(state.user_state);
|
|
874
|
+
this.applyState(state);
|
|
875
|
+
return state;
|
|
876
|
+
}
|
|
827
877
|
// ===========================================================================
|
|
828
878
|
// Internal — Polling (ported from PollingController)
|
|
829
879
|
// ===========================================================================
|
|
@@ -852,6 +902,7 @@ var Session = class extends TypedEventEmitter {
|
|
|
852
902
|
this.userState
|
|
853
903
|
);
|
|
854
904
|
if (!this.pollTimer) return;
|
|
905
|
+
this.assertUserStateAligned(state.user_state);
|
|
855
906
|
this.applyState(state);
|
|
856
907
|
if (!state.is_processing && this.walletRequests.length === 0) {
|
|
857
908
|
this.stopPolling();
|
|
@@ -953,10 +1004,22 @@ var Session = class extends TypedEventEmitter {
|
|
|
953
1004
|
throw new Error("Session is closed");
|
|
954
1005
|
}
|
|
955
1006
|
}
|
|
1007
|
+
assertUserStateAligned(actualUserState) {
|
|
1008
|
+
if (!this.userState) {
|
|
1009
|
+
return;
|
|
1010
|
+
}
|
|
1011
|
+
if (!actualUserState || !isSubsetMatch(this.userState, actualUserState)) {
|
|
1012
|
+
const expected = JSON.stringify(sortJson(this.userState));
|
|
1013
|
+
const actual = JSON.stringify(sortJson(actualUserState != null ? actualUserState : null));
|
|
1014
|
+
throw new Error(
|
|
1015
|
+
`Backend user_state mismatch. expected subset=${expected} actual=${actual}`
|
|
1016
|
+
);
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
956
1019
|
};
|
|
957
1020
|
export {
|
|
958
1021
|
AomiClient,
|
|
959
|
-
Session,
|
|
1022
|
+
ClientSession as Session,
|
|
960
1023
|
TypedEventEmitter,
|
|
961
1024
|
isAsyncCallback,
|
|
962
1025
|
isInlineCall,
|