@aomi-labs/client 0.1.11 → 0.1.12
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/cli.js +81 -24
- package/dist/index.cjs +81 -24
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +81 -24
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -729,6 +729,22 @@ function createSseSubscriber({
|
|
|
729
729
|
// src/client.ts
|
|
730
730
|
var SESSION_ID_HEADER = "X-Session-Id";
|
|
731
731
|
var API_KEY_HEADER = "X-API-Key";
|
|
732
|
+
function joinApiPath(baseUrl, path) {
|
|
733
|
+
const normalizedBase = baseUrl === "/" ? "" : baseUrl.replace(/\/+$/, "");
|
|
734
|
+
const normalizedPath = path.startsWith("/") ? path : `/${path}`;
|
|
735
|
+
return `${normalizedBase}${normalizedPath}` || normalizedPath;
|
|
736
|
+
}
|
|
737
|
+
function buildApiUrl(baseUrl, path, query) {
|
|
738
|
+
const url = joinApiPath(baseUrl, path);
|
|
739
|
+
if (!query) return url;
|
|
740
|
+
const params = new URLSearchParams();
|
|
741
|
+
for (const [key, value] of Object.entries(query)) {
|
|
742
|
+
if (value === void 0) continue;
|
|
743
|
+
params.set(key, value);
|
|
744
|
+
}
|
|
745
|
+
const queryString = params.toString();
|
|
746
|
+
return queryString ? `${url}?${queryString}` : url;
|
|
747
|
+
}
|
|
732
748
|
function toQueryString(payload) {
|
|
733
749
|
const params = new URLSearchParams();
|
|
734
750
|
for (const [key, value] of Object.entries(payload)) {
|
|
@@ -777,11 +793,10 @@ var AomiClient = class {
|
|
|
777
793
|
* Fetch current session state (messages, processing status, title).
|
|
778
794
|
*/
|
|
779
795
|
async fetchState(sessionId, userState) {
|
|
780
|
-
const url =
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
const response = await fetch(url.toString(), {
|
|
796
|
+
const url = buildApiUrl(this.baseUrl, "/api/state", {
|
|
797
|
+
user_state: userState ? JSON.stringify(userState) : void 0
|
|
798
|
+
});
|
|
799
|
+
const response = await fetch(url, {
|
|
785
800
|
headers: withSessionHeader(sessionId)
|
|
786
801
|
});
|
|
787
802
|
if (!response.ok) {
|
|
@@ -851,7 +866,9 @@ var AomiClient = class {
|
|
|
851
866
|
* List all threads for a wallet address.
|
|
852
867
|
*/
|
|
853
868
|
async listThreads(publicKey) {
|
|
854
|
-
const url =
|
|
869
|
+
const url = buildApiUrl(this.baseUrl, "/api/sessions", {
|
|
870
|
+
public_key: publicKey
|
|
871
|
+
});
|
|
855
872
|
const response = await fetch(url);
|
|
856
873
|
if (!response.ok) {
|
|
857
874
|
throw new Error(`Failed to fetch threads: HTTP ${response.status}`);
|
|
@@ -862,7 +879,10 @@ var AomiClient = class {
|
|
|
862
879
|
* Get a single thread by ID.
|
|
863
880
|
*/
|
|
864
881
|
async getThread(sessionId) {
|
|
865
|
-
const url =
|
|
882
|
+
const url = buildApiUrl(
|
|
883
|
+
this.baseUrl,
|
|
884
|
+
`/api/sessions/${encodeURIComponent(sessionId)}`
|
|
885
|
+
);
|
|
866
886
|
const response = await fetch(url, {
|
|
867
887
|
headers: withSessionHeader(sessionId)
|
|
868
888
|
});
|
|
@@ -877,7 +897,7 @@ var AomiClient = class {
|
|
|
877
897
|
async createThread(threadId, publicKey) {
|
|
878
898
|
const body = {};
|
|
879
899
|
if (publicKey) body.public_key = publicKey;
|
|
880
|
-
const url =
|
|
900
|
+
const url = buildApiUrl(this.baseUrl, "/api/sessions");
|
|
881
901
|
const response = await fetch(url, {
|
|
882
902
|
method: "POST",
|
|
883
903
|
headers: withSessionHeader(threadId, {
|
|
@@ -894,7 +914,10 @@ var AomiClient = class {
|
|
|
894
914
|
* Delete a thread by ID.
|
|
895
915
|
*/
|
|
896
916
|
async deleteThread(sessionId) {
|
|
897
|
-
const url =
|
|
917
|
+
const url = buildApiUrl(
|
|
918
|
+
this.baseUrl,
|
|
919
|
+
`/api/sessions/${encodeURIComponent(sessionId)}`
|
|
920
|
+
);
|
|
898
921
|
const response = await fetch(url, {
|
|
899
922
|
method: "DELETE",
|
|
900
923
|
headers: withSessionHeader(sessionId)
|
|
@@ -907,7 +930,10 @@ var AomiClient = class {
|
|
|
907
930
|
* Rename a thread.
|
|
908
931
|
*/
|
|
909
932
|
async renameThread(sessionId, newTitle) {
|
|
910
|
-
const url =
|
|
933
|
+
const url = buildApiUrl(
|
|
934
|
+
this.baseUrl,
|
|
935
|
+
`/api/sessions/${encodeURIComponent(sessionId)}`
|
|
936
|
+
);
|
|
911
937
|
const response = await fetch(url, {
|
|
912
938
|
method: "PATCH",
|
|
913
939
|
headers: withSessionHeader(sessionId, {
|
|
@@ -923,7 +949,10 @@ var AomiClient = class {
|
|
|
923
949
|
* Archive a thread.
|
|
924
950
|
*/
|
|
925
951
|
async archiveThread(sessionId) {
|
|
926
|
-
const url =
|
|
952
|
+
const url = buildApiUrl(
|
|
953
|
+
this.baseUrl,
|
|
954
|
+
`/api/sessions/${encodeURIComponent(sessionId)}/archive`
|
|
955
|
+
);
|
|
927
956
|
const response = await fetch(url, {
|
|
928
957
|
method: "POST",
|
|
929
958
|
headers: withSessionHeader(sessionId)
|
|
@@ -936,7 +965,10 @@ var AomiClient = class {
|
|
|
936
965
|
* Unarchive a thread.
|
|
937
966
|
*/
|
|
938
967
|
async unarchiveThread(sessionId) {
|
|
939
|
-
const url =
|
|
968
|
+
const url = buildApiUrl(
|
|
969
|
+
this.baseUrl,
|
|
970
|
+
`/api/sessions/${encodeURIComponent(sessionId)}/unarchive`
|
|
971
|
+
);
|
|
940
972
|
const response = await fetch(url, {
|
|
941
973
|
method: "POST",
|
|
942
974
|
headers: withSessionHeader(sessionId)
|
|
@@ -952,11 +984,10 @@ var AomiClient = class {
|
|
|
952
984
|
* Get system events for a session.
|
|
953
985
|
*/
|
|
954
986
|
async getSystemEvents(sessionId, count) {
|
|
955
|
-
const url =
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
const response = await fetch(url.toString(), {
|
|
987
|
+
const url = buildApiUrl(this.baseUrl, "/api/events", {
|
|
988
|
+
count: count !== void 0 ? String(count) : void 0
|
|
989
|
+
});
|
|
990
|
+
const response = await fetch(url, {
|
|
960
991
|
headers: withSessionHeader(sessionId)
|
|
961
992
|
});
|
|
962
993
|
if (!response.ok) {
|
|
@@ -973,16 +1004,15 @@ var AomiClient = class {
|
|
|
973
1004
|
*/
|
|
974
1005
|
async getApps(sessionId, options) {
|
|
975
1006
|
var _a3;
|
|
976
|
-
const url =
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
}
|
|
1007
|
+
const url = buildApiUrl(this.baseUrl, "/api/control/apps", {
|
|
1008
|
+
public_key: options == null ? void 0 : options.publicKey
|
|
1009
|
+
});
|
|
980
1010
|
const apiKey = (_a3 = options == null ? void 0 : options.apiKey) != null ? _a3 : this.apiKey;
|
|
981
1011
|
const headers = new Headers(withSessionHeader(sessionId));
|
|
982
1012
|
if (apiKey) {
|
|
983
1013
|
headers.set(API_KEY_HEADER, apiKey);
|
|
984
1014
|
}
|
|
985
|
-
const response = await fetch(url
|
|
1015
|
+
const response = await fetch(url, { headers });
|
|
986
1016
|
if (!response.ok) {
|
|
987
1017
|
throw new Error(`Failed to get apps: HTTP ${response.status}`);
|
|
988
1018
|
}
|
|
@@ -993,13 +1023,13 @@ var AomiClient = class {
|
|
|
993
1023
|
*/
|
|
994
1024
|
async getModels(sessionId, options) {
|
|
995
1025
|
var _a3;
|
|
996
|
-
const url =
|
|
1026
|
+
const url = buildApiUrl(this.baseUrl, "/api/control/models");
|
|
997
1027
|
const apiKey = (_a3 = options == null ? void 0 : options.apiKey) != null ? _a3 : this.apiKey;
|
|
998
1028
|
const headers = new Headers(withSessionHeader(sessionId));
|
|
999
1029
|
if (apiKey) {
|
|
1000
1030
|
headers.set(API_KEY_HEADER, apiKey);
|
|
1001
1031
|
}
|
|
1002
|
-
const response = await fetch(url
|
|
1032
|
+
const response = await fetch(url, {
|
|
1003
1033
|
headers
|
|
1004
1034
|
});
|
|
1005
1035
|
if (!response.ok) {
|
|
@@ -1228,6 +1258,9 @@ function toViemSignTypedDataArgs(payload) {
|
|
|
1228
1258
|
}
|
|
1229
1259
|
|
|
1230
1260
|
// src/session.ts
|
|
1261
|
+
function isRecord(value) {
|
|
1262
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1263
|
+
}
|
|
1231
1264
|
function sortJson(value) {
|
|
1232
1265
|
if (Array.isArray(value)) {
|
|
1233
1266
|
return value.map((entry) => sortJson(entry));
|
|
@@ -1450,6 +1483,30 @@ var ClientSession = class extends TypedEventEmitter {
|
|
|
1450
1483
|
this.publicKey = address;
|
|
1451
1484
|
}
|
|
1452
1485
|
}
|
|
1486
|
+
addExtValue(key, value) {
|
|
1487
|
+
var _a3;
|
|
1488
|
+
const current = (_a3 = this.userState) != null ? _a3 : {};
|
|
1489
|
+
const currentExt = isRecord(current["ext"]) ? current["ext"] : {};
|
|
1490
|
+
this.resolveUserState(__spreadProps(__spreadValues({}, current), {
|
|
1491
|
+
ext: __spreadProps(__spreadValues({}, currentExt), {
|
|
1492
|
+
[key]: value
|
|
1493
|
+
})
|
|
1494
|
+
}));
|
|
1495
|
+
}
|
|
1496
|
+
removeExtValue(key) {
|
|
1497
|
+
if (!this.userState) return;
|
|
1498
|
+
const currentExt = this.userState["ext"];
|
|
1499
|
+
if (!isRecord(currentExt)) return;
|
|
1500
|
+
const nextExt = __spreadValues({}, currentExt);
|
|
1501
|
+
delete nextExt[key];
|
|
1502
|
+
const nextState = __spreadValues({}, this.userState);
|
|
1503
|
+
if (Object.keys(nextExt).length === 0) {
|
|
1504
|
+
delete nextState["ext"];
|
|
1505
|
+
} else {
|
|
1506
|
+
nextState["ext"] = nextExt;
|
|
1507
|
+
}
|
|
1508
|
+
this.resolveUserState(nextState);
|
|
1509
|
+
}
|
|
1453
1510
|
resolveWallet(address, chainId) {
|
|
1454
1511
|
this.resolveUserState({ address, chainId: chainId != null ? chainId : 1, isConnected: true });
|
|
1455
1512
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -254,6 +254,22 @@ function createSseSubscriber({
|
|
|
254
254
|
// src/client.ts
|
|
255
255
|
var SESSION_ID_HEADER = "X-Session-Id";
|
|
256
256
|
var API_KEY_HEADER = "X-API-Key";
|
|
257
|
+
function joinApiPath(baseUrl, path) {
|
|
258
|
+
const normalizedBase = baseUrl === "/" ? "" : baseUrl.replace(/\/+$/, "");
|
|
259
|
+
const normalizedPath = path.startsWith("/") ? path : `/${path}`;
|
|
260
|
+
return `${normalizedBase}${normalizedPath}` || normalizedPath;
|
|
261
|
+
}
|
|
262
|
+
function buildApiUrl(baseUrl, path, query) {
|
|
263
|
+
const url = joinApiPath(baseUrl, path);
|
|
264
|
+
if (!query) return url;
|
|
265
|
+
const params = new URLSearchParams();
|
|
266
|
+
for (const [key, value] of Object.entries(query)) {
|
|
267
|
+
if (value === void 0) continue;
|
|
268
|
+
params.set(key, value);
|
|
269
|
+
}
|
|
270
|
+
const queryString = params.toString();
|
|
271
|
+
return queryString ? `${url}?${queryString}` : url;
|
|
272
|
+
}
|
|
257
273
|
function toQueryString(payload) {
|
|
258
274
|
const params = new URLSearchParams();
|
|
259
275
|
for (const [key, value] of Object.entries(payload)) {
|
|
@@ -302,11 +318,10 @@ var AomiClient = class {
|
|
|
302
318
|
* Fetch current session state (messages, processing status, title).
|
|
303
319
|
*/
|
|
304
320
|
async fetchState(sessionId, userState) {
|
|
305
|
-
const url =
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
const response = await fetch(url.toString(), {
|
|
321
|
+
const url = buildApiUrl(this.baseUrl, "/api/state", {
|
|
322
|
+
user_state: userState ? JSON.stringify(userState) : void 0
|
|
323
|
+
});
|
|
324
|
+
const response = await fetch(url, {
|
|
310
325
|
headers: withSessionHeader(sessionId)
|
|
311
326
|
});
|
|
312
327
|
if (!response.ok) {
|
|
@@ -376,7 +391,9 @@ var AomiClient = class {
|
|
|
376
391
|
* List all threads for a wallet address.
|
|
377
392
|
*/
|
|
378
393
|
async listThreads(publicKey) {
|
|
379
|
-
const url =
|
|
394
|
+
const url = buildApiUrl(this.baseUrl, "/api/sessions", {
|
|
395
|
+
public_key: publicKey
|
|
396
|
+
});
|
|
380
397
|
const response = await fetch(url);
|
|
381
398
|
if (!response.ok) {
|
|
382
399
|
throw new Error(`Failed to fetch threads: HTTP ${response.status}`);
|
|
@@ -387,7 +404,10 @@ var AomiClient = class {
|
|
|
387
404
|
* Get a single thread by ID.
|
|
388
405
|
*/
|
|
389
406
|
async getThread(sessionId) {
|
|
390
|
-
const url =
|
|
407
|
+
const url = buildApiUrl(
|
|
408
|
+
this.baseUrl,
|
|
409
|
+
`/api/sessions/${encodeURIComponent(sessionId)}`
|
|
410
|
+
);
|
|
391
411
|
const response = await fetch(url, {
|
|
392
412
|
headers: withSessionHeader(sessionId)
|
|
393
413
|
});
|
|
@@ -402,7 +422,7 @@ var AomiClient = class {
|
|
|
402
422
|
async createThread(threadId, publicKey) {
|
|
403
423
|
const body = {};
|
|
404
424
|
if (publicKey) body.public_key = publicKey;
|
|
405
|
-
const url =
|
|
425
|
+
const url = buildApiUrl(this.baseUrl, "/api/sessions");
|
|
406
426
|
const response = await fetch(url, {
|
|
407
427
|
method: "POST",
|
|
408
428
|
headers: withSessionHeader(threadId, {
|
|
@@ -419,7 +439,10 @@ var AomiClient = class {
|
|
|
419
439
|
* Delete a thread by ID.
|
|
420
440
|
*/
|
|
421
441
|
async deleteThread(sessionId) {
|
|
422
|
-
const url =
|
|
442
|
+
const url = buildApiUrl(
|
|
443
|
+
this.baseUrl,
|
|
444
|
+
`/api/sessions/${encodeURIComponent(sessionId)}`
|
|
445
|
+
);
|
|
423
446
|
const response = await fetch(url, {
|
|
424
447
|
method: "DELETE",
|
|
425
448
|
headers: withSessionHeader(sessionId)
|
|
@@ -432,7 +455,10 @@ var AomiClient = class {
|
|
|
432
455
|
* Rename a thread.
|
|
433
456
|
*/
|
|
434
457
|
async renameThread(sessionId, newTitle) {
|
|
435
|
-
const url =
|
|
458
|
+
const url = buildApiUrl(
|
|
459
|
+
this.baseUrl,
|
|
460
|
+
`/api/sessions/${encodeURIComponent(sessionId)}`
|
|
461
|
+
);
|
|
436
462
|
const response = await fetch(url, {
|
|
437
463
|
method: "PATCH",
|
|
438
464
|
headers: withSessionHeader(sessionId, {
|
|
@@ -448,7 +474,10 @@ var AomiClient = class {
|
|
|
448
474
|
* Archive a thread.
|
|
449
475
|
*/
|
|
450
476
|
async archiveThread(sessionId) {
|
|
451
|
-
const url =
|
|
477
|
+
const url = buildApiUrl(
|
|
478
|
+
this.baseUrl,
|
|
479
|
+
`/api/sessions/${encodeURIComponent(sessionId)}/archive`
|
|
480
|
+
);
|
|
452
481
|
const response = await fetch(url, {
|
|
453
482
|
method: "POST",
|
|
454
483
|
headers: withSessionHeader(sessionId)
|
|
@@ -461,7 +490,10 @@ var AomiClient = class {
|
|
|
461
490
|
* Unarchive a thread.
|
|
462
491
|
*/
|
|
463
492
|
async unarchiveThread(sessionId) {
|
|
464
|
-
const url =
|
|
493
|
+
const url = buildApiUrl(
|
|
494
|
+
this.baseUrl,
|
|
495
|
+
`/api/sessions/${encodeURIComponent(sessionId)}/unarchive`
|
|
496
|
+
);
|
|
465
497
|
const response = await fetch(url, {
|
|
466
498
|
method: "POST",
|
|
467
499
|
headers: withSessionHeader(sessionId)
|
|
@@ -477,11 +509,10 @@ var AomiClient = class {
|
|
|
477
509
|
* Get system events for a session.
|
|
478
510
|
*/
|
|
479
511
|
async getSystemEvents(sessionId, count) {
|
|
480
|
-
const url =
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
const response = await fetch(url.toString(), {
|
|
512
|
+
const url = buildApiUrl(this.baseUrl, "/api/events", {
|
|
513
|
+
count: count !== void 0 ? String(count) : void 0
|
|
514
|
+
});
|
|
515
|
+
const response = await fetch(url, {
|
|
485
516
|
headers: withSessionHeader(sessionId)
|
|
486
517
|
});
|
|
487
518
|
if (!response.ok) {
|
|
@@ -498,16 +529,15 @@ var AomiClient = class {
|
|
|
498
529
|
*/
|
|
499
530
|
async getApps(sessionId, options) {
|
|
500
531
|
var _a;
|
|
501
|
-
const url =
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
}
|
|
532
|
+
const url = buildApiUrl(this.baseUrl, "/api/control/apps", {
|
|
533
|
+
public_key: options == null ? void 0 : options.publicKey
|
|
534
|
+
});
|
|
505
535
|
const apiKey = (_a = options == null ? void 0 : options.apiKey) != null ? _a : this.apiKey;
|
|
506
536
|
const headers = new Headers(withSessionHeader(sessionId));
|
|
507
537
|
if (apiKey) {
|
|
508
538
|
headers.set(API_KEY_HEADER, apiKey);
|
|
509
539
|
}
|
|
510
|
-
const response = await fetch(url
|
|
540
|
+
const response = await fetch(url, { headers });
|
|
511
541
|
if (!response.ok) {
|
|
512
542
|
throw new Error(`Failed to get apps: HTTP ${response.status}`);
|
|
513
543
|
}
|
|
@@ -518,13 +548,13 @@ var AomiClient = class {
|
|
|
518
548
|
*/
|
|
519
549
|
async getModels(sessionId, options) {
|
|
520
550
|
var _a;
|
|
521
|
-
const url =
|
|
551
|
+
const url = buildApiUrl(this.baseUrl, "/api/control/models");
|
|
522
552
|
const apiKey = (_a = options == null ? void 0 : options.apiKey) != null ? _a : this.apiKey;
|
|
523
553
|
const headers = new Headers(withSessionHeader(sessionId));
|
|
524
554
|
if (apiKey) {
|
|
525
555
|
headers.set(API_KEY_HEADER, apiKey);
|
|
526
556
|
}
|
|
527
|
-
const response = await fetch(url
|
|
557
|
+
const response = await fetch(url, {
|
|
528
558
|
headers
|
|
529
559
|
});
|
|
530
560
|
if (!response.ok) {
|
|
@@ -753,6 +783,9 @@ function toViemSignTypedDataArgs(payload) {
|
|
|
753
783
|
}
|
|
754
784
|
|
|
755
785
|
// src/session.ts
|
|
786
|
+
function isRecord(value) {
|
|
787
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
788
|
+
}
|
|
756
789
|
function sortJson(value) {
|
|
757
790
|
if (Array.isArray(value)) {
|
|
758
791
|
return value.map((entry) => sortJson(entry));
|
|
@@ -975,6 +1008,30 @@ var ClientSession = class extends TypedEventEmitter {
|
|
|
975
1008
|
this.publicKey = address;
|
|
976
1009
|
}
|
|
977
1010
|
}
|
|
1011
|
+
addExtValue(key, value) {
|
|
1012
|
+
var _a;
|
|
1013
|
+
const current = (_a = this.userState) != null ? _a : {};
|
|
1014
|
+
const currentExt = isRecord(current["ext"]) ? current["ext"] : {};
|
|
1015
|
+
this.resolveUserState(__spreadProps(__spreadValues({}, current), {
|
|
1016
|
+
ext: __spreadProps(__spreadValues({}, currentExt), {
|
|
1017
|
+
[key]: value
|
|
1018
|
+
})
|
|
1019
|
+
}));
|
|
1020
|
+
}
|
|
1021
|
+
removeExtValue(key) {
|
|
1022
|
+
if (!this.userState) return;
|
|
1023
|
+
const currentExt = this.userState["ext"];
|
|
1024
|
+
if (!isRecord(currentExt)) return;
|
|
1025
|
+
const nextExt = __spreadValues({}, currentExt);
|
|
1026
|
+
delete nextExt[key];
|
|
1027
|
+
const nextState = __spreadValues({}, this.userState);
|
|
1028
|
+
if (Object.keys(nextExt).length === 0) {
|
|
1029
|
+
delete nextState["ext"];
|
|
1030
|
+
} else {
|
|
1031
|
+
nextState["ext"] = nextExt;
|
|
1032
|
+
}
|
|
1033
|
+
this.resolveUserState(nextState);
|
|
1034
|
+
}
|
|
978
1035
|
resolveWallet(address, chainId) {
|
|
979
1036
|
this.resolveUserState({ address, chainId: chainId != null ? chainId : 1, isConnected: true });
|
|
980
1037
|
}
|