@aomi-labs/client 0.1.15 → 0.1.16

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 CHANGED
@@ -22,7 +22,7 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
22
22
  // package.json
23
23
  var package_default = {
24
24
  name: "@aomi-labs/client",
25
- version: "0.1.15",
25
+ version: "0.1.16",
26
26
  description: "Platform-agnostic TypeScript client for the Aomi backend API",
27
27
  type: "module",
28
28
  main: "./dist/index.cjs",
@@ -278,6 +278,7 @@ function readStoredSession(path) {
278
278
  const fallbackLocalId = (_a3 = parseSessionFileLocalId(basename(path))) != null ? _a3 : 0;
279
279
  return {
280
280
  sessionId: parsed.sessionId,
281
+ clientId: parsed.clientId,
281
282
  baseUrl: parsed.baseUrl,
282
283
  app: parsed.app,
283
284
  model: parsed.model,
@@ -286,6 +287,7 @@ function readStoredSession(path) {
286
287
  chainId: parsed.chainId,
287
288
  pendingTxs: parsed.pendingTxs,
288
289
  signedTxs: parsed.signedTxs,
290
+ secretHandles: parsed.secretHandles,
289
291
  localId: typeof parsed.localId === "number" && parsed.localId > 0 ? parsed.localId : fallbackLocalId,
290
292
  createdAt: typeof parsed.createdAt === "number" && parsed.createdAt > 0 ? parsed.createdAt : Date.now(),
291
293
  updatedAt: typeof parsed.updatedAt === "number" && parsed.updatedAt > 0 ? parsed.updatedAt : Date.now()
@@ -1148,6 +1150,30 @@ var AomiClient = class {
1148
1150
  }
1149
1151
  };
1150
1152
 
1153
+ // src/types.ts
1154
+ var CLIENT_TYPE_TS_CLI = "ts_cli";
1155
+ function addUserStateExt(userState, key, value) {
1156
+ const currentExt = userState["ext"];
1157
+ const extRecord = typeof currentExt === "object" && currentExt !== null && !Array.isArray(currentExt) ? currentExt : {};
1158
+ return __spreadProps(__spreadValues({}, userState), {
1159
+ ext: __spreadProps(__spreadValues({}, extRecord), {
1160
+ [key]: value
1161
+ })
1162
+ });
1163
+ }
1164
+ function isInlineCall(event) {
1165
+ return "InlineCall" in event;
1166
+ }
1167
+ function isSystemNotice(event) {
1168
+ return "SystemNotice" in event;
1169
+ }
1170
+ function isSystemError(event) {
1171
+ return "SystemError" in event;
1172
+ }
1173
+ function isAsyncCallback(event) {
1174
+ return "AsyncCallback" in event;
1175
+ }
1176
+
1151
1177
  // src/event-emitter.ts
1152
1178
  var TypedEventEmitter = class {
1153
1179
  constructor() {
@@ -1220,20 +1246,6 @@ var TypedEventEmitter = class {
1220
1246
  }
1221
1247
  };
1222
1248
 
1223
- // src/types.ts
1224
- function isInlineCall(event) {
1225
- return "InlineCall" in event;
1226
- }
1227
- function isSystemNotice(event) {
1228
- return "SystemNotice" in event;
1229
- }
1230
- function isSystemError(event) {
1231
- return "SystemError" in event;
1232
- }
1233
- function isAsyncCallback(event) {
1234
- return "AsyncCallback" in event;
1235
- }
1236
-
1237
1249
  // src/event-unwrap.ts
1238
1250
  function unwrapSystemEvent(event) {
1239
1251
  var _a3;
@@ -1391,7 +1403,7 @@ function isSubsetMatch(expected, actual) {
1391
1403
  }
1392
1404
  var ClientSession = class extends TypedEventEmitter {
1393
1405
  constructor(clientOrOptions, sessionOptions) {
1394
- var _a3, _b, _c;
1406
+ var _a3, _b, _c, _d, _e;
1395
1407
  super();
1396
1408
  // Internal state
1397
1409
  this.pollTimer = null;
@@ -1408,8 +1420,9 @@ var ClientSession = class extends TypedEventEmitter {
1408
1420
  this.app = (_b = sessionOptions == null ? void 0 : sessionOptions.app) != null ? _b : "default";
1409
1421
  this.publicKey = sessionOptions == null ? void 0 : sessionOptions.publicKey;
1410
1422
  this.apiKey = sessionOptions == null ? void 0 : sessionOptions.apiKey;
1411
- this.userState = sessionOptions == null ? void 0 : sessionOptions.userState;
1412
- this.pollIntervalMs = (_c = sessionOptions == null ? void 0 : sessionOptions.pollIntervalMs) != null ? _c : 500;
1423
+ this.userState = (sessionOptions == null ? void 0 : sessionOptions.clientType) ? addUserStateExt((_c = sessionOptions == null ? void 0 : sessionOptions.userState) != null ? _c : {}, "client_type", sessionOptions.clientType) : sessionOptions == null ? void 0 : sessionOptions.userState;
1424
+ this.clientId = (_d = sessionOptions == null ? void 0 : sessionOptions.clientId) != null ? _d : crypto.randomUUID();
1425
+ this.pollIntervalMs = (_e = sessionOptions == null ? void 0 : sessionOptions.pollIntervalMs) != null ? _e : 500;
1413
1426
  this.logger = sessionOptions == null ? void 0 : sessionOptions.logger;
1414
1427
  this.unsubscribeSSE = this.client.subscribeSSE(
1415
1428
  this.sessionId,
@@ -1434,7 +1447,8 @@ var ClientSession = class extends TypedEventEmitter {
1434
1447
  app: this.app,
1435
1448
  publicKey: this.publicKey,
1436
1449
  apiKey: this.apiKey,
1437
- userState: this.userState
1450
+ userState: this.userState,
1451
+ clientId: this.clientId
1438
1452
  });
1439
1453
  this.assertUserStateAligned(response.user_state);
1440
1454
  this.applyState(response);
@@ -1458,7 +1472,8 @@ var ClientSession = class extends TypedEventEmitter {
1458
1472
  app: this.app,
1459
1473
  publicKey: this.publicKey,
1460
1474
  apiKey: this.apiKey,
1461
- userState: this.userState
1475
+ userState: this.userState,
1476
+ clientId: this.clientId
1462
1477
  });
1463
1478
  this.assertUserStateAligned(response.user_state);
1464
1479
  this.applyState(response);
@@ -1580,6 +1595,10 @@ var ClientSession = class extends TypedEventEmitter {
1580
1595
  this.publicKey = address;
1581
1596
  }
1582
1597
  }
1598
+ setClientType(clientType) {
1599
+ var _a3;
1600
+ this.resolveUserState(addUserStateExt((_a3 = this.userState) != null ? _a3 : {}, "client_type", clientType));
1601
+ }
1583
1602
  addExtValue(key, value) {
1584
1603
  var _a3;
1585
1604
  const current = (_a3 = this.userState) != null ? _a3 : {};
@@ -1609,7 +1628,7 @@ var ClientSession = class extends TypedEventEmitter {
1609
1628
  }
1610
1629
  async syncUserState() {
1611
1630
  this.assertOpen();
1612
- const state = await this.client.fetchState(this.sessionId, this.userState);
1631
+ const state = await this.client.fetchState(this.sessionId, this.userState, this.clientId);
1613
1632
  this.assertUserStateAligned(state.user_state);
1614
1633
  this.applyState(state);
1615
1634
  return state;
@@ -1639,7 +1658,8 @@ var ClientSession = class extends TypedEventEmitter {
1639
1658
  try {
1640
1659
  const state = await this.client.fetchState(
1641
1660
  this.sessionId,
1642
- this.userState
1661
+ this.userState,
1662
+ this.clientId
1643
1663
  );
1644
1664
  if (!this.pollTimer) return;
1645
1665
  this.assertUserStateAligned(state.user_state);
@@ -1760,9 +1780,6 @@ var ClientSession = class extends TypedEventEmitter {
1760
1780
 
1761
1781
  // src/cli/user-state.ts
1762
1782
  function buildCliUserState(publicKey, chainId) {
1763
- if (publicKey === void 0 && chainId === void 0) {
1764
- return void 0;
1765
- }
1766
1783
  const userState = {};
1767
1784
  if (publicKey !== void 0) {
1768
1785
  userState.address = publicKey;
@@ -1771,7 +1788,7 @@ function buildCliUserState(publicKey, chainId) {
1771
1788
  if (chainId !== void 0) {
1772
1789
  userState.chainId = chainId;
1773
1790
  }
1774
- return userState;
1791
+ return addUserStateExt(userState, "client_type", CLIENT_TYPE_TS_CLI);
1775
1792
  }
1776
1793
 
1777
1794
  // src/cli/context.ts
@@ -1785,7 +1802,8 @@ function getOrCreateSession(runtime) {
1785
1802
  app: config.app,
1786
1803
  apiKey: config.apiKey,
1787
1804
  publicKey: config.publicKey,
1788
- chainId: config.chain
1805
+ chainId: config.chain,
1806
+ clientId: crypto.randomUUID()
1789
1807
  };
1790
1808
  writeState(state);
1791
1809
  } else {
@@ -1810,21 +1828,23 @@ function getOrCreateSession(runtime) {
1810
1828
  state.chainId = config.chain;
1811
1829
  changed = true;
1812
1830
  }
1831
+ if (!state.clientId) {
1832
+ state.clientId = crypto.randomUUID();
1833
+ changed = true;
1834
+ }
1813
1835
  if (changed) writeState(state);
1814
1836
  }
1815
1837
  const session = new ClientSession(
1816
1838
  { baseUrl: state.baseUrl, apiKey: state.apiKey },
1817
1839
  {
1818
1840
  sessionId: state.sessionId,
1841
+ clientId: state.clientId,
1819
1842
  app: state.app,
1820
1843
  apiKey: state.apiKey,
1821
1844
  publicKey: state.publicKey
1822
1845
  }
1823
1846
  );
1824
- const userState = buildCliUserState(state.publicKey, state.chainId);
1825
- if (userState) {
1826
- session.resolveUserState(userState);
1827
- }
1847
+ session.resolveUserState(buildCliUserState(state.publicKey, state.chainId));
1828
1848
  return { session, state };
1829
1849
  }
1830
1850
  function createControlClient(runtime) {
@@ -1969,11 +1989,9 @@ async function chatCommand(runtime) {
1969
1989
  const verbose = runtime.parsed.flags["verbose"] === "true" || runtime.parsed.flags["v"] === "true";
1970
1990
  const { session, state } = getOrCreateSession(runtime);
1971
1991
  try {
1992
+ await ingestSecretsIfPresent(runtime, state, session.client);
1972
1993
  await applyRequestedModelIfPresent(runtime, session, state);
1973
- const userState = buildCliUserState(state.publicKey, state.chainId);
1974
- if (userState) {
1975
- session.resolveUserState(userState);
1976
- }
1994
+ session.resolveUserState(buildCliUserState(state.publicKey, state.chainId));
1977
1995
  const capturedRequests = [];
1978
1996
  let printedAgentCount = 0;
1979
1997
  const seenToolResults = /* @__PURE__ */ new Set();
@@ -2360,7 +2378,7 @@ async function statusCommand(runtime) {
2360
2378
  }
2361
2379
  const { session, state } = getOrCreateSession(runtime);
2362
2380
  try {
2363
- const apiState = await session.client.fetchState(state.sessionId);
2381
+ const apiState = await session.client.fetchState(state.sessionId, void 0, state.clientId);
2364
2382
  console.log(
2365
2383
  JSON.stringify(
2366
2384
  {
@@ -2640,7 +2658,7 @@ async function logCommand(runtime) {
2640
2658
  }
2641
2659
  const { session, state } = getOrCreateSession(runtime);
2642
2660
  try {
2643
- const apiState = await session.client.fetchState(state.sessionId);
2661
+ const apiState = await session.client.fetchState(state.sessionId, void 0, state.clientId);
2644
2662
  const messages = (_a3 = apiState.messages) != null ? _a3 : [];
2645
2663
  const pendingTxs = (_b = state.pendingTxs) != null ? _b : [];
2646
2664
  const signedTxs = (_c = state.signedTxs) != null ? _c : [];
@@ -2767,6 +2785,11 @@ async function secretCommand(runtime) {
2767
2785
  if (subcommand === "clear") {
2768
2786
  const { session, state } = getOrCreateSession(runtime);
2769
2787
  try {
2788
+ if (!state.clientId) {
2789
+ console.log("No secrets configured.");
2790
+ printDataFileLocation();
2791
+ return;
2792
+ }
2770
2793
  await session.client.clearSecrets(state.clientId);
2771
2794
  state.secretHandles = {};
2772
2795
  writeState(state);
@@ -2788,7 +2811,7 @@ async function fetchRemoteSessionStats(record) {
2788
2811
  apiKey: record.state.apiKey
2789
2812
  });
2790
2813
  try {
2791
- const apiState = await client.fetchState(record.sessionId);
2814
+ const apiState = await client.fetchState(record.sessionId, void 0, record.state.clientId);
2792
2815
  const messages = (_a3 = apiState.messages) != null ? _a3 : [];
2793
2816
  return {
2794
2817
  topic: (_b = apiState.title) != null ? _b : "Untitled Session",
@@ -3490,10 +3513,7 @@ function createSessionFromState(state) {
3490
3513
  publicKey: state.publicKey
3491
3514
  }
3492
3515
  );
3493
- const userState = buildCliUserState(state.publicKey, state.chainId);
3494
- if (userState) {
3495
- session.resolveUserState(userState);
3496
- }
3516
+ session.resolveUserState(buildCliUserState(state.publicKey, state.chainId));
3497
3517
  return session;
3498
3518
  }
3499
3519
  async function persistResolvedSignerState(session, state, address, chainId) {
package/dist/index.cjs CHANGED
@@ -48,10 +48,13 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
48
48
  var index_exports = {};
49
49
  __export(index_exports, {
50
50
  AomiClient: () => AomiClient,
51
+ CLIENT_TYPE_TS_CLI: () => CLIENT_TYPE_TS_CLI,
52
+ CLIENT_TYPE_WEB_UI: () => CLIENT_TYPE_WEB_UI,
51
53
  DEFAULT_AA_CONFIG: () => DEFAULT_AA_CONFIG,
52
54
  Session: () => ClientSession,
53
55
  TypedEventEmitter: () => TypedEventEmitter,
54
56
  adaptSmartAccount: () => adaptSmartAccount,
57
+ addUserStateExt: () => addUserStateExt,
55
58
  buildAAExecutionPlan: () => buildAAExecutionPlan,
56
59
  createAAProviderState: () => createAAProviderState,
57
60
  createAlchemyAAProvider: () => createAlchemyAAProvider,
@@ -615,6 +618,17 @@ var AomiClient = class {
615
618
  };
616
619
 
617
620
  // src/types.ts
621
+ var CLIENT_TYPE_TS_CLI = "ts_cli";
622
+ var CLIENT_TYPE_WEB_UI = "web_ui";
623
+ function addUserStateExt(userState, key, value) {
624
+ const currentExt = userState["ext"];
625
+ const extRecord = typeof currentExt === "object" && currentExt !== null && !Array.isArray(currentExt) ? currentExt : {};
626
+ return __spreadProps(__spreadValues({}, userState), {
627
+ ext: __spreadProps(__spreadValues({}, extRecord), {
628
+ [key]: value
629
+ })
630
+ });
631
+ }
618
632
  function isInlineCall(event) {
619
633
  return "InlineCall" in event;
620
634
  }
@@ -857,7 +871,7 @@ function isSubsetMatch(expected, actual) {
857
871
  }
858
872
  var ClientSession = class extends TypedEventEmitter {
859
873
  constructor(clientOrOptions, sessionOptions) {
860
- var _a, _b, _c;
874
+ var _a, _b, _c, _d, _e;
861
875
  super();
862
876
  // Internal state
863
877
  this.pollTimer = null;
@@ -874,8 +888,9 @@ var ClientSession = class extends TypedEventEmitter {
874
888
  this.app = (_b = sessionOptions == null ? void 0 : sessionOptions.app) != null ? _b : "default";
875
889
  this.publicKey = sessionOptions == null ? void 0 : sessionOptions.publicKey;
876
890
  this.apiKey = sessionOptions == null ? void 0 : sessionOptions.apiKey;
877
- this.userState = sessionOptions == null ? void 0 : sessionOptions.userState;
878
- this.pollIntervalMs = (_c = sessionOptions == null ? void 0 : sessionOptions.pollIntervalMs) != null ? _c : 500;
891
+ this.userState = (sessionOptions == null ? void 0 : sessionOptions.clientType) ? addUserStateExt((_c = sessionOptions == null ? void 0 : sessionOptions.userState) != null ? _c : {}, "client_type", sessionOptions.clientType) : sessionOptions == null ? void 0 : sessionOptions.userState;
892
+ this.clientId = (_d = sessionOptions == null ? void 0 : sessionOptions.clientId) != null ? _d : crypto.randomUUID();
893
+ this.pollIntervalMs = (_e = sessionOptions == null ? void 0 : sessionOptions.pollIntervalMs) != null ? _e : 500;
879
894
  this.logger = sessionOptions == null ? void 0 : sessionOptions.logger;
880
895
  this.unsubscribeSSE = this.client.subscribeSSE(
881
896
  this.sessionId,
@@ -900,7 +915,8 @@ var ClientSession = class extends TypedEventEmitter {
900
915
  app: this.app,
901
916
  publicKey: this.publicKey,
902
917
  apiKey: this.apiKey,
903
- userState: this.userState
918
+ userState: this.userState,
919
+ clientId: this.clientId
904
920
  });
905
921
  this.assertUserStateAligned(response.user_state);
906
922
  this.applyState(response);
@@ -924,7 +940,8 @@ var ClientSession = class extends TypedEventEmitter {
924
940
  app: this.app,
925
941
  publicKey: this.publicKey,
926
942
  apiKey: this.apiKey,
927
- userState: this.userState
943
+ userState: this.userState,
944
+ clientId: this.clientId
928
945
  });
929
946
  this.assertUserStateAligned(response.user_state);
930
947
  this.applyState(response);
@@ -1046,6 +1063,10 @@ var ClientSession = class extends TypedEventEmitter {
1046
1063
  this.publicKey = address;
1047
1064
  }
1048
1065
  }
1066
+ setClientType(clientType) {
1067
+ var _a;
1068
+ this.resolveUserState(addUserStateExt((_a = this.userState) != null ? _a : {}, "client_type", clientType));
1069
+ }
1049
1070
  addExtValue(key, value) {
1050
1071
  var _a;
1051
1072
  const current = (_a = this.userState) != null ? _a : {};
@@ -1075,7 +1096,7 @@ var ClientSession = class extends TypedEventEmitter {
1075
1096
  }
1076
1097
  async syncUserState() {
1077
1098
  this.assertOpen();
1078
- const state = await this.client.fetchState(this.sessionId, this.userState);
1099
+ const state = await this.client.fetchState(this.sessionId, this.userState, this.clientId);
1079
1100
  this.assertUserStateAligned(state.user_state);
1080
1101
  this.applyState(state);
1081
1102
  return state;
@@ -1105,7 +1126,8 @@ var ClientSession = class extends TypedEventEmitter {
1105
1126
  try {
1106
1127
  const state = await this.client.fetchState(
1107
1128
  this.sessionId,
1108
- this.userState
1129
+ this.userState,
1130
+ this.clientId
1109
1131
  );
1110
1132
  if (!this.pollTimer) return;
1111
1133
  this.assertUserStateAligned(state.user_state);
@@ -2029,10 +2051,13 @@ async function createPimlicoAAState(options) {
2029
2051
  // Annotate the CommonJS export names for ESM import in node:
2030
2052
  0 && (module.exports = {
2031
2053
  AomiClient,
2054
+ CLIENT_TYPE_TS_CLI,
2055
+ CLIENT_TYPE_WEB_UI,
2032
2056
  DEFAULT_AA_CONFIG,
2033
2057
  Session,
2034
2058
  TypedEventEmitter,
2035
2059
  adaptSmartAccount,
2060
+ addUserStateExt,
2036
2061
  buildAAExecutionPlan,
2037
2062
  createAAProviderState,
2038
2063
  createAlchemyAAProvider,