@aomi-labs/client 0.1.14 → 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.14",
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",
@@ -133,22 +133,38 @@ function parseAAMode(value) {
133
133
  }
134
134
  fatal("Unsupported AA mode. Use `4337` or `7702`.");
135
135
  }
136
+ function parseSecret(value, secrets) {
137
+ const eqIdx = value.indexOf("=");
138
+ if (eqIdx > 0) {
139
+ secrets[value.slice(0, eqIdx)] = value.slice(eqIdx + 1);
140
+ }
141
+ }
136
142
  function parseArgs(argv) {
137
143
  const raw = argv.slice(2);
138
144
  const command = raw[0] && !raw[0].startsWith("-") ? raw[0] : void 0;
139
145
  const rest = command ? raw.slice(1) : raw;
140
146
  const positional = [];
141
147
  const flags = {};
148
+ const secrets = {};
142
149
  for (let i = 0; i < rest.length; i++) {
143
150
  const arg = rest[i];
144
151
  if (arg.startsWith("--") && arg.includes("=")) {
145
152
  const [key, ...val] = arg.slice(2).split("=");
146
- flags[key] = val.join("=");
153
+ const value = val.join("=");
154
+ if (key === "secret") {
155
+ parseSecret(value, secrets);
156
+ } else {
157
+ flags[key] = value;
158
+ }
147
159
  } else if (arg.startsWith("--")) {
148
160
  const key = arg.slice(2);
149
161
  const next = rest[i + 1];
150
162
  if (next && !next.startsWith("-")) {
151
- flags[key] = next;
163
+ if (key === "secret") {
164
+ parseSecret(next, secrets);
165
+ } else {
166
+ flags[key] = next;
167
+ }
152
168
  i++;
153
169
  } else {
154
170
  flags[key] = "true";
@@ -159,7 +175,7 @@ function parseArgs(argv) {
159
175
  positional.push(arg);
160
176
  }
161
177
  }
162
- return { command, positional, flags };
178
+ return { command, positional, flags, secrets };
163
179
  }
164
180
  function getConfig(parsed) {
165
181
  var _a3, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
@@ -188,6 +204,7 @@ function getConfig(parsed) {
188
204
  privateKey: (_j = parsed.flags["private-key"]) != null ? _j : process.env.PRIVATE_KEY,
189
205
  chainRpcUrl: (_k = parsed.flags["rpc-url"]) != null ? _k : process.env.CHAIN_RPC_URL,
190
206
  chain: parseChainId((_l = parsed.flags["chain"]) != null ? _l : process.env.AOMI_CHAIN_ID),
207
+ secrets: parsed.secrets,
191
208
  execution,
192
209
  aaProvider,
193
210
  aaMode
@@ -238,6 +255,7 @@ function toSessionFilePath(localId) {
238
255
  function toCliSessionState(stored) {
239
256
  return {
240
257
  sessionId: stored.sessionId,
258
+ clientId: stored.clientId,
241
259
  baseUrl: stored.baseUrl,
242
260
  app: stored.app,
243
261
  model: stored.model,
@@ -245,7 +263,8 @@ function toCliSessionState(stored) {
245
263
  publicKey: stored.publicKey,
246
264
  chainId: stored.chainId,
247
265
  pendingTxs: stored.pendingTxs,
248
- signedTxs: stored.signedTxs
266
+ signedTxs: stored.signedTxs,
267
+ secretHandles: stored.secretHandles
249
268
  };
250
269
  }
251
270
  function readStoredSession(path) {
@@ -259,6 +278,7 @@ function readStoredSession(path) {
259
278
  const fallbackLocalId = (_a3 = parseSessionFileLocalId(basename(path))) != null ? _a3 : 0;
260
279
  return {
261
280
  sessionId: parsed.sessionId,
281
+ clientId: parsed.clientId,
262
282
  baseUrl: parsed.baseUrl,
263
283
  app: parsed.app,
264
284
  model: parsed.model,
@@ -267,6 +287,7 @@ function readStoredSession(path) {
267
287
  chainId: parsed.chainId,
268
288
  pendingTxs: parsed.pendingTxs,
269
289
  signedTxs: parsed.signedTxs,
290
+ secretHandles: parsed.secretHandles,
270
291
  localId: typeof parsed.localId === "number" && parsed.localId > 0 ? parsed.localId : fallbackLocalId,
271
292
  createdAt: typeof parsed.createdAt === "number" && parsed.createdAt > 0 ? parsed.createdAt : Date.now(),
272
293
  updatedAt: typeof parsed.updatedAt === "number" && parsed.updatedAt > 0 ? parsed.updatedAt : Date.now()
@@ -1129,6 +1150,30 @@ var AomiClient = class {
1129
1150
  }
1130
1151
  };
1131
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
+
1132
1177
  // src/event-emitter.ts
1133
1178
  var TypedEventEmitter = class {
1134
1179
  constructor() {
@@ -1201,20 +1246,6 @@ var TypedEventEmitter = class {
1201
1246
  }
1202
1247
  };
1203
1248
 
1204
- // src/types.ts
1205
- function isInlineCall(event) {
1206
- return "InlineCall" in event;
1207
- }
1208
- function isSystemNotice(event) {
1209
- return "SystemNotice" in event;
1210
- }
1211
- function isSystemError(event) {
1212
- return "SystemError" in event;
1213
- }
1214
- function isAsyncCallback(event) {
1215
- return "AsyncCallback" in event;
1216
- }
1217
-
1218
1249
  // src/event-unwrap.ts
1219
1250
  function unwrapSystemEvent(event) {
1220
1251
  var _a3;
@@ -1372,7 +1403,7 @@ function isSubsetMatch(expected, actual) {
1372
1403
  }
1373
1404
  var ClientSession = class extends TypedEventEmitter {
1374
1405
  constructor(clientOrOptions, sessionOptions) {
1375
- var _a3, _b, _c;
1406
+ var _a3, _b, _c, _d, _e;
1376
1407
  super();
1377
1408
  // Internal state
1378
1409
  this.pollTimer = null;
@@ -1389,8 +1420,9 @@ var ClientSession = class extends TypedEventEmitter {
1389
1420
  this.app = (_b = sessionOptions == null ? void 0 : sessionOptions.app) != null ? _b : "default";
1390
1421
  this.publicKey = sessionOptions == null ? void 0 : sessionOptions.publicKey;
1391
1422
  this.apiKey = sessionOptions == null ? void 0 : sessionOptions.apiKey;
1392
- this.userState = sessionOptions == null ? void 0 : sessionOptions.userState;
1393
- 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;
1394
1426
  this.logger = sessionOptions == null ? void 0 : sessionOptions.logger;
1395
1427
  this.unsubscribeSSE = this.client.subscribeSSE(
1396
1428
  this.sessionId,
@@ -1415,7 +1447,8 @@ var ClientSession = class extends TypedEventEmitter {
1415
1447
  app: this.app,
1416
1448
  publicKey: this.publicKey,
1417
1449
  apiKey: this.apiKey,
1418
- userState: this.userState
1450
+ userState: this.userState,
1451
+ clientId: this.clientId
1419
1452
  });
1420
1453
  this.assertUserStateAligned(response.user_state);
1421
1454
  this.applyState(response);
@@ -1439,7 +1472,8 @@ var ClientSession = class extends TypedEventEmitter {
1439
1472
  app: this.app,
1440
1473
  publicKey: this.publicKey,
1441
1474
  apiKey: this.apiKey,
1442
- userState: this.userState
1475
+ userState: this.userState,
1476
+ clientId: this.clientId
1443
1477
  });
1444
1478
  this.assertUserStateAligned(response.user_state);
1445
1479
  this.applyState(response);
@@ -1561,6 +1595,10 @@ var ClientSession = class extends TypedEventEmitter {
1561
1595
  this.publicKey = address;
1562
1596
  }
1563
1597
  }
1598
+ setClientType(clientType) {
1599
+ var _a3;
1600
+ this.resolveUserState(addUserStateExt((_a3 = this.userState) != null ? _a3 : {}, "client_type", clientType));
1601
+ }
1564
1602
  addExtValue(key, value) {
1565
1603
  var _a3;
1566
1604
  const current = (_a3 = this.userState) != null ? _a3 : {};
@@ -1590,7 +1628,7 @@ var ClientSession = class extends TypedEventEmitter {
1590
1628
  }
1591
1629
  async syncUserState() {
1592
1630
  this.assertOpen();
1593
- const state = await this.client.fetchState(this.sessionId, this.userState);
1631
+ const state = await this.client.fetchState(this.sessionId, this.userState, this.clientId);
1594
1632
  this.assertUserStateAligned(state.user_state);
1595
1633
  this.applyState(state);
1596
1634
  return state;
@@ -1620,7 +1658,8 @@ var ClientSession = class extends TypedEventEmitter {
1620
1658
  try {
1621
1659
  const state = await this.client.fetchState(
1622
1660
  this.sessionId,
1623
- this.userState
1661
+ this.userState,
1662
+ this.clientId
1624
1663
  );
1625
1664
  if (!this.pollTimer) return;
1626
1665
  this.assertUserStateAligned(state.user_state);
@@ -1741,9 +1780,6 @@ var ClientSession = class extends TypedEventEmitter {
1741
1780
 
1742
1781
  // src/cli/user-state.ts
1743
1782
  function buildCliUserState(publicKey, chainId) {
1744
- if (publicKey === void 0 && chainId === void 0) {
1745
- return void 0;
1746
- }
1747
1783
  const userState = {};
1748
1784
  if (publicKey !== void 0) {
1749
1785
  userState.address = publicKey;
@@ -1752,7 +1788,7 @@ function buildCliUserState(publicKey, chainId) {
1752
1788
  if (chainId !== void 0) {
1753
1789
  userState.chainId = chainId;
1754
1790
  }
1755
- return userState;
1791
+ return addUserStateExt(userState, "client_type", CLIENT_TYPE_TS_CLI);
1756
1792
  }
1757
1793
 
1758
1794
  // src/cli/context.ts
@@ -1766,7 +1802,8 @@ function getOrCreateSession(runtime) {
1766
1802
  app: config.app,
1767
1803
  apiKey: config.apiKey,
1768
1804
  publicKey: config.publicKey,
1769
- chainId: config.chain
1805
+ chainId: config.chain,
1806
+ clientId: crypto.randomUUID()
1770
1807
  };
1771
1808
  writeState(state);
1772
1809
  } else {
@@ -1791,21 +1828,23 @@ function getOrCreateSession(runtime) {
1791
1828
  state.chainId = config.chain;
1792
1829
  changed = true;
1793
1830
  }
1831
+ if (!state.clientId) {
1832
+ state.clientId = crypto.randomUUID();
1833
+ changed = true;
1834
+ }
1794
1835
  if (changed) writeState(state);
1795
1836
  }
1796
1837
  const session = new ClientSession(
1797
1838
  { baseUrl: state.baseUrl, apiKey: state.apiKey },
1798
1839
  {
1799
1840
  sessionId: state.sessionId,
1841
+ clientId: state.clientId,
1800
1842
  app: state.app,
1801
1843
  apiKey: state.apiKey,
1802
1844
  publicKey: state.publicKey
1803
1845
  }
1804
1846
  );
1805
- const userState = buildCliUserState(state.publicKey, state.chainId);
1806
- if (userState) {
1807
- session.resolveUserState(userState);
1808
- }
1847
+ session.resolveUserState(buildCliUserState(state.publicKey, state.chainId));
1809
1848
  return { session, state };
1810
1849
  }
1811
1850
  function createControlClient(runtime) {
@@ -1822,6 +1861,22 @@ async function applyModelSelection(session, state, model) {
1822
1861
  state.model = model;
1823
1862
  writeState(state);
1824
1863
  }
1864
+ async function ingestSecretsIfPresent(runtime, state, client) {
1865
+ var _a3;
1866
+ const secrets = runtime.config.secrets;
1867
+ if (Object.keys(secrets).length === 0) return {};
1868
+ if (!state.clientId) {
1869
+ state.clientId = crypto.randomUUID();
1870
+ writeState(state);
1871
+ }
1872
+ const response = await client.ingestSecrets(
1873
+ state.clientId,
1874
+ secrets
1875
+ );
1876
+ state.secretHandles = __spreadValues(__spreadValues({}, (_a3 = state.secretHandles) != null ? _a3 : {}), response.handles);
1877
+ writeState(state);
1878
+ return response.handles;
1879
+ }
1825
1880
  async function applyRequestedModelIfPresent(runtime, session, state) {
1826
1881
  const requestedModel = runtime.config.model;
1827
1882
  if (!requestedModel || requestedModel === state.model) {
@@ -1934,11 +1989,9 @@ async function chatCommand(runtime) {
1934
1989
  const verbose = runtime.parsed.flags["verbose"] === "true" || runtime.parsed.flags["v"] === "true";
1935
1990
  const { session, state } = getOrCreateSession(runtime);
1936
1991
  try {
1992
+ await ingestSecretsIfPresent(runtime, state, session.client);
1937
1993
  await applyRequestedModelIfPresent(runtime, session, state);
1938
- const userState = buildCliUserState(state.publicKey, state.chainId);
1939
- if (userState) {
1940
- session.resolveUserState(userState);
1941
- }
1994
+ session.resolveUserState(buildCliUserState(state.publicKey, state.chainId));
1942
1995
  const capturedRequests = [];
1943
1996
  let printedAgentCount = 0;
1944
1997
  const seenToolResults = /* @__PURE__ */ new Set();
@@ -2325,7 +2378,7 @@ async function statusCommand(runtime) {
2325
2378
  }
2326
2379
  const { session, state } = getOrCreateSession(runtime);
2327
2380
  try {
2328
- const apiState = await session.client.fetchState(state.sessionId);
2381
+ const apiState = await session.client.fetchState(state.sessionId, void 0, state.clientId);
2329
2382
  console.log(
2330
2383
  JSON.stringify(
2331
2384
  {
@@ -2605,7 +2658,7 @@ async function logCommand(runtime) {
2605
2658
  }
2606
2659
  const { session, state } = getOrCreateSession(runtime);
2607
2660
  try {
2608
- const apiState = await session.client.fetchState(state.sessionId);
2661
+ const apiState = await session.client.fetchState(state.sessionId, void 0, state.clientId);
2609
2662
  const messages = (_a3 = apiState.messages) != null ? _a3 : [];
2610
2663
  const pendingTxs = (_b = state.pendingTxs) != null ? _b : [];
2611
2664
  const signedTxs = (_c = state.signedTxs) != null ? _c : [];
@@ -2681,6 +2734,75 @@ function closeCommand(runtime) {
2681
2734
  console.log("Session closed");
2682
2735
  }
2683
2736
 
2737
+ // src/cli/commands/secrets.ts
2738
+ async function ingestSecretsCommand(runtime) {
2739
+ const secretEntries = Object.entries(runtime.config.secrets);
2740
+ if (secretEntries.length === 0) {
2741
+ fatal("Usage: aomi --secret NAME=value [NAME=value ...]");
2742
+ }
2743
+ const { session, state } = getOrCreateSession(runtime);
2744
+ try {
2745
+ const handles = await ingestSecretsIfPresent(
2746
+ runtime,
2747
+ state,
2748
+ session.client
2749
+ );
2750
+ const names = Object.keys(handles).sort();
2751
+ console.log(
2752
+ `Configured ${names.length} secret${names.length === 1 ? "" : "s"} for session ${state.sessionId}.`
2753
+ );
2754
+ for (const name of names) {
2755
+ console.log(`${name} ${handles[name]}`);
2756
+ }
2757
+ printDataFileLocation();
2758
+ } finally {
2759
+ session.close();
2760
+ }
2761
+ }
2762
+ async function secretCommand(runtime) {
2763
+ var _a3;
2764
+ const subcommand = runtime.parsed.positional[0];
2765
+ if (!subcommand || subcommand === "list") {
2766
+ const state = readState();
2767
+ if (!state) {
2768
+ console.log("No active session");
2769
+ printDataFileLocation();
2770
+ return;
2771
+ }
2772
+ const secretHandles = (_a3 = state.secretHandles) != null ? _a3 : {};
2773
+ const names = Object.keys(secretHandles).sort();
2774
+ if (names.length === 0) {
2775
+ console.log("No secrets configured.");
2776
+ printDataFileLocation();
2777
+ return;
2778
+ }
2779
+ for (const name of names) {
2780
+ console.log(`${name} ${secretHandles[name]}`);
2781
+ }
2782
+ printDataFileLocation();
2783
+ return;
2784
+ }
2785
+ if (subcommand === "clear") {
2786
+ const { session, state } = getOrCreateSession(runtime);
2787
+ try {
2788
+ if (!state.clientId) {
2789
+ console.log("No secrets configured.");
2790
+ printDataFileLocation();
2791
+ return;
2792
+ }
2793
+ await session.client.clearSecrets(state.clientId);
2794
+ state.secretHandles = {};
2795
+ writeState(state);
2796
+ console.log("Cleared all secrets for the active session.");
2797
+ printDataFileLocation();
2798
+ } finally {
2799
+ session.close();
2800
+ }
2801
+ return;
2802
+ }
2803
+ fatal("Usage: aomi secret list\n aomi secret clear");
2804
+ }
2805
+
2684
2806
  // src/cli/commands/sessions.ts
2685
2807
  async function fetchRemoteSessionStats(record) {
2686
2808
  var _a3, _b;
@@ -2689,7 +2811,7 @@ async function fetchRemoteSessionStats(record) {
2689
2811
  apiKey: record.state.apiKey
2690
2812
  });
2691
2813
  try {
2692
- const apiState = await client.fetchState(record.sessionId);
2814
+ const apiState = await client.fetchState(record.sessionId, void 0, record.state.clientId);
2693
2815
  const messages = (_a3 = apiState.messages) != null ? _a3 : [];
2694
2816
  return {
2695
2817
  topic: (_b = apiState.title) != null ? _b : "Untitled Session",
@@ -3391,10 +3513,7 @@ function createSessionFromState(state) {
3391
3513
  publicKey: state.publicKey
3392
3514
  }
3393
3515
  );
3394
- const userState = buildCliUserState(state.publicKey, state.chainId);
3395
- if (userState) {
3396
- session.resolveUserState(userState);
3397
- }
3516
+ session.resolveUserState(buildCliUserState(state.publicKey, state.chainId));
3398
3517
  return session;
3399
3518
  }
3400
3519
  async function persistResolvedSignerState(session, state, address, chainId) {
@@ -3729,6 +3848,8 @@ Usage:
3729
3848
  aomi tx List pending and signed transactions
3730
3849
  aomi sign <tx-id> [<tx-id> ...] [--eoa | --aa] [--aa-provider <name>] [--aa-mode <mode>]
3731
3850
  Sign and submit a pending transaction
3851
+ aomi secret list List configured secrets for the active session
3852
+ aomi secret clear Clear all secrets for the active session
3732
3853
  aomi status Show current session state
3733
3854
  aomi events List system events
3734
3855
  aomi close Close the current session
@@ -3742,6 +3863,7 @@ Options:
3742
3863
  --public-key <addr> Wallet address (so the agent knows your wallet)
3743
3864
  --private-key <key> Hex private key for signing
3744
3865
  --rpc-url <url> RPC URL for transaction submission
3866
+ --secret NAME=value Ingest a secret (repeatable, e.g. --secret X_API_KEY=abc)
3745
3867
  --verbose, -v Show tool calls and streaming output (for chat)
3746
3868
  --version, -V Print the installed CLI version
3747
3869
 
@@ -3777,8 +3899,9 @@ Environment (overridden by flags):
3777
3899
  `.trim());
3778
3900
  }
3779
3901
  async function main(runtime) {
3780
- var _a3, _b;
3781
- const command = (_b = (_a3 = runtime.parsed.command) != null ? _a3 : runtime.parsed.flags["version"] || runtime.parsed.flags["V"] ? "version" : void 0) != null ? _b : runtime.parsed.flags["help"] || runtime.parsed.flags["h"] ? "help" : void 0;
3902
+ var _a3, _b, _c;
3903
+ const hasSecrets = Object.keys(runtime.parsed.secrets).length > 0;
3904
+ const command = (_c = (_b = (_a3 = runtime.parsed.command) != null ? _a3 : hasSecrets ? "ingest-secrets" : void 0) != null ? _b : runtime.parsed.flags["version"] || runtime.parsed.flags["V"] ? "version" : void 0) != null ? _c : runtime.parsed.flags["help"] || runtime.parsed.flags["h"] ? "help" : void 0;
3782
3905
  switch (command) {
3783
3906
  case "chat":
3784
3907
  await chatCommand(runtime);
@@ -3810,6 +3933,12 @@ async function main(runtime) {
3810
3933
  case "events":
3811
3934
  await eventsCommand(runtime);
3812
3935
  break;
3936
+ case "secret":
3937
+ await secretCommand(runtime);
3938
+ break;
3939
+ case "ingest-secrets":
3940
+ await ingestSecretsCommand(runtime);
3941
+ break;
3813
3942
  case "close":
3814
3943
  closeCommand(runtime);
3815
3944
  break;
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,