@aomi-labs/react 0.3.13 → 0.3.15

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.js CHANGED
@@ -38,6 +38,10 @@ import {
38
38
  hydrateTxPayloadFromUserState,
39
39
  toAAWalletCalls,
40
40
  toAAWalletCall,
41
+ appendFeeCallToPayload,
42
+ buildFeeAAWalletCall,
43
+ normalizeSimulatedFee,
44
+ MAX_AUTO_FEE_WEI,
41
45
  executeWalletCalls,
42
46
  DISABLED_PROVIDER_STATE,
43
47
  parseChainId,
@@ -86,6 +90,7 @@ var logThreadMetadataChange = (source, threadId, prev, next) => {
86
90
  function initThreadControl() {
87
91
  return {
88
92
  model: null,
93
+ modelMode: "auto",
89
94
  app: null,
90
95
  controlDirty: false,
91
96
  isProcessing: false
@@ -229,16 +234,36 @@ var ThreadStore = class {
229
234
  }
230
235
  };
231
236
 
237
+ // packages/react/src/utils/model-selection.ts
238
+ var PREFERRED_DEFAULT_MODEL_PATTERNS = [
239
+ /^claude-4\.5-haiku/i,
240
+ /^claude.*haiku/i,
241
+ /^gpt-4o-mini/i,
242
+ /^gemini.*flash/i
243
+ ];
244
+ function resolveAutoModel(models) {
245
+ var _a;
246
+ if (models.length === 0) return null;
247
+ for (const pattern of PREFERRED_DEFAULT_MODEL_PATTERNS) {
248
+ const match = models.find((model) => pattern.test(model));
249
+ if (match) return match;
250
+ }
251
+ return (_a = models[0]) != null ? _a : null;
252
+ }
253
+
232
254
  // packages/react/src/contexts/control-context.tsx
233
255
  import { jsx } from "react/jsx-runtime";
234
256
  var API_KEY_STORAGE_KEY = "aomi_api_key";
235
257
  var CLIENT_ID_STORAGE_KEY = "aomi_client_id";
236
258
  var PROVIDER_KEYS_STORAGE_KEY = "aomi_provider_keys";
259
+ var MODEL_SELECTION_STORAGE_KEY = "aomi_model_selection";
237
260
  var PROVIDER_KEY_SECRET_PREFIX = "PROVIDER_KEY:";
238
261
  function getOrCreateClientId() {
239
262
  var _a, _b, _c, _d, _e;
240
263
  try {
241
- const storedClientId = (_a = globalThis.localStorage) == null ? void 0 : _a.getItem(CLIENT_ID_STORAGE_KEY);
264
+ const storedClientId = (_a = globalThis.localStorage) == null ? void 0 : _a.getItem(
265
+ CLIENT_ID_STORAGE_KEY
266
+ );
242
267
  if (storedClientId && storedClientId.trim().length > 0) {
243
268
  return storedClientId;
244
269
  }
@@ -255,6 +280,49 @@ function getDefaultApp(apps) {
255
280
  var _a;
256
281
  return apps.includes("default") ? "default" : (_a = apps[0]) != null ? _a : null;
257
282
  }
283
+ function readStoredModelPreference() {
284
+ var _a;
285
+ try {
286
+ const raw = (_a = globalThis.localStorage) == null ? void 0 : _a.getItem(MODEL_SELECTION_STORAGE_KEY);
287
+ if (!raw) return { mode: "auto", model: null };
288
+ const parsed = JSON.parse(raw);
289
+ return {
290
+ mode: parsed.mode === "manual" ? "manual" : "auto",
291
+ model: typeof parsed.model === "string" ? parsed.model : null
292
+ };
293
+ } catch (e) {
294
+ return { mode: "auto", model: null };
295
+ }
296
+ }
297
+ function writeStoredModelPreference(preference) {
298
+ var _a;
299
+ try {
300
+ (_a = globalThis.localStorage) == null ? void 0 : _a.setItem(
301
+ MODEL_SELECTION_STORAGE_KEY,
302
+ JSON.stringify(preference)
303
+ );
304
+ } catch (e) {
305
+ }
306
+ }
307
+ function resolvePreferredModelSelection(preference, models, defaultModel) {
308
+ var _a;
309
+ if (preference.mode === "manual" && preference.model && models.includes(preference.model)) {
310
+ return preference;
311
+ }
312
+ if (preference.mode === "auto") {
313
+ return {
314
+ mode: "auto",
315
+ model: (_a = resolveAutoModel(models)) != null ? _a : defaultModel
316
+ };
317
+ }
318
+ return {
319
+ mode: "auto",
320
+ model: defaultModel != null ? defaultModel : resolveAutoModel(models)
321
+ };
322
+ }
323
+ function getFallbackModel(models, defaultModel) {
324
+ return defaultModel != null ? defaultModel : resolveAutoModel(models);
325
+ }
258
326
  function resolveAuthorizedApp(app, authorizedApps, defaultApp) {
259
327
  if (app && authorizedApps.includes(app)) {
260
328
  return app;
@@ -374,13 +442,10 @@ function ControlContextProvider({
374
442
  const fetchApps = async () => {
375
443
  var _a2;
376
444
  try {
377
- const apps = await aomiClientRef.current.getApps(
378
- sessionIdRef.current,
379
- {
380
- publicKey: publicKeyRef.current,
381
- apiKey: (_a2 = stateRef.current.apiKey) != null ? _a2 : void 0
382
- }
383
- );
445
+ const apps = await aomiClientRef.current.getApps(sessionIdRef.current, {
446
+ publicKey: publicKeyRef.current,
447
+ apiKey: (_a2 = stateRef.current.apiKey) != null ? _a2 : void 0
448
+ });
384
449
  const defaultApp = getDefaultApp(apps);
385
450
  setStateInternal((prev) => __spreadProps(__spreadValues({}, prev), {
386
451
  authorizedApps: apps,
@@ -402,13 +467,10 @@ function ControlContextProvider({
402
467
  const models = await aomiClientRef.current.getModels(
403
468
  sessionIdRef.current
404
469
  );
405
- setStateInternal((prev) => {
406
- var _a2;
407
- return __spreadProps(__spreadValues({}, prev), {
408
- availableModels: models,
409
- defaultModel: (_a2 = models[0]) != null ? _a2 : null
410
- });
411
- });
470
+ setStateInternal((prev) => __spreadProps(__spreadValues({}, prev), {
471
+ availableModels: models,
472
+ defaultModel: resolveAutoModel(models)
473
+ }));
412
474
  } catch (error) {
413
475
  console.error("Failed to fetch models:", error);
414
476
  }
@@ -491,26 +553,20 @@ function ControlContextProvider({
491
553
  () => stateRef.current.providerKeys,
492
554
  []
493
555
  );
494
- const hasProviderKey = useCallback(
495
- (provider) => {
496
- const keys = stateRef.current.providerKeys;
497
- if (provider) return provider in keys;
498
- return Object.keys(keys).length > 0;
499
- },
500
- []
501
- );
556
+ const hasProviderKey = useCallback((provider) => {
557
+ const keys = stateRef.current.providerKeys;
558
+ if (provider) return provider in keys;
559
+ return Object.keys(keys).length > 0;
560
+ }, []);
502
561
  const getAvailableModels = useCallback(async () => {
503
562
  try {
504
563
  const models = await aomiClientRef.current.getModels(
505
564
  sessionIdRef.current
506
565
  );
507
- setStateInternal((prev) => {
508
- var _a2, _b2;
509
- return __spreadProps(__spreadValues({}, prev), {
510
- availableModels: models,
511
- defaultModel: (_b2 = (_a2 = prev.defaultModel) != null ? _a2 : models[0]) != null ? _b2 : null
512
- });
513
- });
566
+ setStateInternal((prev) => __spreadProps(__spreadValues({}, prev), {
567
+ availableModels: models,
568
+ defaultModel: resolveAutoModel(models)
569
+ }));
514
570
  return models;
515
571
  } catch (error) {
516
572
  console.error("Failed to fetch models:", error);
@@ -520,13 +576,10 @@ function ControlContextProvider({
520
576
  const getAuthorizedApps = useCallback(async () => {
521
577
  var _a2;
522
578
  try {
523
- const apps = await aomiClientRef.current.getApps(
524
- sessionIdRef.current,
525
- {
526
- publicKey: publicKeyRef.current,
527
- apiKey: (_a2 = stateRef.current.apiKey) != null ? _a2 : void 0
528
- }
529
- );
579
+ const apps = await aomiClientRef.current.getApps(sessionIdRef.current, {
580
+ publicKey: publicKeyRef.current,
581
+ apiKey: (_a2 = stateRef.current.apiKey) != null ? _a2 : void 0
582
+ });
530
583
  const defaultApp = getDefaultApp(apps);
531
584
  setStateInternal((prev) => __spreadProps(__spreadValues({}, prev), {
532
585
  authorizedApps: apps,
@@ -547,6 +600,19 @@ function ControlContextProvider({
547
600
  const metadata = getThreadMetadataRef.current(sessionIdRef.current);
548
601
  return (_a2 = metadata == null ? void 0 : metadata.control) != null ? _a2 : initThreadControl();
549
602
  }, []);
603
+ const getPreferredThreadControl = useCallback(() => {
604
+ const preference = readStoredModelPreference();
605
+ const selection = resolvePreferredModelSelection(
606
+ preference,
607
+ stateRef.current.availableModels,
608
+ stateRef.current.defaultModel
609
+ );
610
+ return __spreadProps(__spreadValues({}, initThreadControl()), {
611
+ model: selection.model,
612
+ modelMode: selection.mode,
613
+ controlDirty: selection.model !== null
614
+ });
615
+ }, []);
550
616
  const getCurrentThreadApp = useCallback(() => {
551
617
  var _a2, _b2, _c;
552
618
  const currentControl = (_b2 = (_a2 = getThreadMetadataRef.current(sessionIdRef.current)) == null ? void 0 : _a2.control) != null ? _b2 : initThreadControl();
@@ -556,60 +622,75 @@ function ControlContextProvider({
556
622
  stateRef.current.defaultApp
557
623
  )) != null ? _c : "default";
558
624
  }, []);
559
- const onModelSelect = useCallback(async (model) => {
560
- var _a2, _b2, _c, _d, _e;
561
- const threadId = sessionIdRef.current;
562
- const currentControl = (_b2 = (_a2 = getThreadMetadataRef.current(threadId)) == null ? void 0 : _a2.control) != null ? _b2 : initThreadControl();
563
- const isProcessing2 = currentControl.isProcessing;
564
- console.log("[control-context] onModelSelect called", {
565
- model,
566
- isProcessing: isProcessing2,
567
- threadId
568
- });
569
- if (isProcessing2) {
570
- console.warn("[control-context] Cannot switch model while processing");
571
- return;
572
- }
573
- const app = (_c = resolveAuthorizedApp(
574
- currentControl.app,
575
- stateRef.current.authorizedApps,
576
- stateRef.current.defaultApp
577
- )) != null ? _c : "default";
578
- console.log("[control-context] onModelSelect updating metadata", {
579
- threadId,
580
- model,
581
- app,
582
- currentControl
583
- });
584
- updateThreadMetadataRef.current(threadId, {
585
- control: __spreadProps(__spreadValues({}, currentControl), {
625
+ const onModelSelect = useCallback(
626
+ async (model, options) => {
627
+ var _a2, _b2, _c, _d, _e, _f, _g, _h;
628
+ const threadId = sessionIdRef.current;
629
+ const currentControl = (_b2 = (_a2 = getThreadMetadataRef.current(threadId)) == null ? void 0 : _a2.control) != null ? _b2 : initThreadControl();
630
+ const isProcessing2 = currentControl.isProcessing;
631
+ const modelMode = (_c = options == null ? void 0 : options.mode) != null ? _c : "manual";
632
+ console.log("[control-context] onModelSelect called", {
633
+ model,
634
+ modelMode,
635
+ isProcessing: isProcessing2,
636
+ threadId
637
+ });
638
+ if (isProcessing2) {
639
+ console.warn("[control-context] Cannot switch model while processing");
640
+ return;
641
+ }
642
+ const app = (_d = resolveAuthorizedApp(
643
+ currentControl.app,
644
+ stateRef.current.authorizedApps,
645
+ stateRef.current.defaultApp
646
+ )) != null ? _d : "default";
647
+ console.log("[control-context] onModelSelect updating metadata", {
648
+ threadId,
586
649
  model,
587
650
  app,
588
- controlDirty: true
589
- })
590
- });
591
- console.log("[control-context] onModelSelect calling backend setModel", {
592
- threadId,
593
- model,
594
- app,
595
- backendUrl: aomiClientRef.current
596
- });
597
- try {
598
- const result = await aomiClientRef.current.setModel(
651
+ currentControl
652
+ });
653
+ updateThreadMetadataRef.current(threadId, {
654
+ control: __spreadProps(__spreadValues({}, currentControl), {
655
+ model,
656
+ modelMode,
657
+ app,
658
+ controlDirty: true
659
+ })
660
+ });
661
+ console.log("[control-context] onModelSelect calling backend setModel", {
599
662
  threadId,
600
663
  model,
601
- {
664
+ app,
665
+ backendUrl: aomiClientRef.current
666
+ });
667
+ try {
668
+ const result = await aomiClientRef.current.setModel(threadId, model, {
602
669
  app,
603
- apiKey: (_d = stateRef.current.apiKey) != null ? _d : void 0,
604
- clientId: (_e = stateRef.current.clientId) != null ? _e : void 0
670
+ apiKey: (_e = stateRef.current.apiKey) != null ? _e : void 0,
671
+ clientId: (_f = stateRef.current.clientId) != null ? _f : void 0
672
+ });
673
+ console.log("[control-context] onModelSelect backend result", result);
674
+ writeStoredModelPreference({
675
+ mode: modelMode,
676
+ model: modelMode === "manual" ? model : null
677
+ });
678
+ const latestControl = (_h = (_g = getThreadMetadataRef.current(threadId)) == null ? void 0 : _g.control) != null ? _h : currentControl;
679
+ if (latestControl.model === model && latestControl.app === app) {
680
+ updateThreadMetadataRef.current(threadId, {
681
+ control: __spreadProps(__spreadValues({}, latestControl), {
682
+ modelMode,
683
+ controlDirty: false
684
+ })
685
+ });
605
686
  }
606
- );
607
- console.log("[control-context] onModelSelect backend result", result);
608
- } catch (err) {
609
- console.error("[control-context] setModel failed:", err);
610
- throw err;
611
- }
612
- }, []);
687
+ } catch (err) {
688
+ console.error("[control-context] setModel failed:", err);
689
+ throw err;
690
+ }
691
+ },
692
+ []
693
+ );
613
694
  const onAppSelect = useCallback((app) => {
614
695
  var _a2, _b2;
615
696
  const threadId = sessionIdRef.current;
@@ -621,9 +702,7 @@ function ControlContextProvider({
621
702
  threadId
622
703
  });
623
704
  if (isProcessing2) {
624
- console.warn(
625
- "[control-context] Cannot switch app while processing"
626
- );
705
+ console.warn("[control-context] Cannot switch app while processing");
627
706
  return;
628
707
  }
629
708
  if (stateRef.current.authorizedApps.length > 0 && !stateRef.current.authorizedApps.includes(app)) {
@@ -655,6 +734,86 @@ function ControlContextProvider({
655
734
  });
656
735
  }
657
736
  }, []);
737
+ const syncCurrentThreadControl = useCallback(async () => {
738
+ var _a2, _b2, _c, _d, _e, _f, _g;
739
+ const threadId = sessionIdRef.current;
740
+ const currentControl = (_b2 = (_a2 = getThreadMetadataRef.current(threadId)) == null ? void 0 : _a2.control) != null ? _b2 : initThreadControl();
741
+ if (!currentControl.controlDirty || currentControl.isProcessing || !currentControl.model) {
742
+ return;
743
+ }
744
+ const app = (_c = resolveAuthorizedApp(
745
+ currentControl.app,
746
+ stateRef.current.authorizedApps,
747
+ stateRef.current.defaultApp
748
+ )) != null ? _c : "default";
749
+ await aomiClientRef.current.setModel(threadId, currentControl.model, {
750
+ app,
751
+ apiKey: (_d = stateRef.current.apiKey) != null ? _d : void 0,
752
+ clientId: (_e = stateRef.current.clientId) != null ? _e : void 0
753
+ });
754
+ const latestControl = (_g = (_f = getThreadMetadataRef.current(threadId)) == null ? void 0 : _f.control) != null ? _g : currentControl;
755
+ if (latestControl.model === currentControl.model && latestControl.app === currentControl.app) {
756
+ updateThreadMetadataRef.current(threadId, {
757
+ control: __spreadProps(__spreadValues({}, latestControl), {
758
+ app,
759
+ controlDirty: false
760
+ })
761
+ });
762
+ }
763
+ }, []);
764
+ useEffect(() => {
765
+ var _a2;
766
+ const threadId = sessionIdRef.current;
767
+ const metadata = getThreadMetadataRef.current(threadId);
768
+ if (!metadata || metadata.control.isProcessing) return;
769
+ const currentControl = metadata.control;
770
+ let nextControl = null;
771
+ if (currentControl.model === null) {
772
+ const preferred = getPreferredThreadControl();
773
+ if (!preferred.model) return;
774
+ nextControl = __spreadProps(__spreadValues({}, currentControl), {
775
+ model: preferred.model,
776
+ modelMode: preferred.modelMode,
777
+ controlDirty: true
778
+ });
779
+ } else if (state.availableModels.length > 0) {
780
+ const currentMode = (_a2 = currentControl.modelMode) != null ? _a2 : "manual";
781
+ if (currentMode === "auto") {
782
+ const autoModel = getFallbackModel(
783
+ state.availableModels,
784
+ state.defaultModel
785
+ );
786
+ if (autoModel && currentControl.model !== autoModel) {
787
+ nextControl = __spreadProps(__spreadValues({}, currentControl), {
788
+ model: autoModel,
789
+ modelMode: "auto",
790
+ controlDirty: true
791
+ });
792
+ }
793
+ } else if (!state.availableModels.includes(currentControl.model)) {
794
+ const fallbackModel = getFallbackModel(
795
+ state.availableModels,
796
+ state.defaultModel
797
+ );
798
+ if (fallbackModel) {
799
+ nextControl = __spreadProps(__spreadValues({}, currentControl), {
800
+ model: fallbackModel,
801
+ modelMode: "auto",
802
+ controlDirty: true
803
+ });
804
+ }
805
+ }
806
+ }
807
+ if (!nextControl) return;
808
+ updateThreadMetadataRef.current(threadId, {
809
+ control: nextControl
810
+ });
811
+ }, [
812
+ getPreferredThreadControl,
813
+ sessionId,
814
+ state.availableModels,
815
+ state.defaultModel
816
+ ]);
658
817
  const getControlState = useCallback(() => stateRef.current, []);
659
818
  const onControlStateChange = useCallback(
660
819
  (callback) => {
@@ -697,6 +856,8 @@ function ControlContextProvider({
697
856
  onAppSelect,
698
857
  isProcessing,
699
858
  markControlSynced,
859
+ syncCurrentThreadControl,
860
+ getPreferredThreadControl,
700
861
  getControlState,
701
862
  onControlStateChange,
702
863
  setState
@@ -1359,7 +1520,8 @@ function buildThreadLists(threadMetadata) {
1359
1520
  function buildThreadListAdapter({
1360
1521
  aomiClientRef,
1361
1522
  threadContext,
1362
- setIsRunning
1523
+ setIsRunning,
1524
+ getInitialControl = initThreadControl
1363
1525
  }) {
1364
1526
  const { regularThreads, archivedThreads } = buildThreadLists(
1365
1527
  threadContext.allThreadsMetadata
@@ -1375,7 +1537,7 @@ function buildThreadListAdapter({
1375
1537
  title: "New Chat",
1376
1538
  status: "regular",
1377
1539
  lastActiveAt: (/* @__PURE__ */ new Date()).toISOString(),
1378
- control: initThreadControl()
1540
+ control: getInitialControl()
1379
1541
  })
1380
1542
  );
1381
1543
  threadContext.setThreadMessages(threadId, []);
@@ -1447,7 +1609,7 @@ function buildThreadListAdapter({
1447
1609
  title: "New Chat",
1448
1610
  status: "regular",
1449
1611
  lastActiveAt: (/* @__PURE__ */ new Date()).toISOString(),
1450
- control: initThreadControl()
1612
+ control: getInitialControl()
1451
1613
  })
1452
1614
  );
1453
1615
  threadContext.setThreadMessages(defaultId, []);
@@ -1609,7 +1771,12 @@ function AomiRuntimeCore({
1609
1771
  const eventContext = useEventContext();
1610
1772
  const notificationContext = useNotification();
1611
1773
  const { user, onUserStateChange, getUserState } = useUser();
1612
- const { getControlState, getCurrentThreadApp } = useControl();
1774
+ const {
1775
+ getControlState,
1776
+ getCurrentThreadApp,
1777
+ getPreferredThreadControl,
1778
+ syncCurrentThreadControl
1779
+ } = useControl();
1613
1780
  const sessionManagerRef = useRef8(null);
1614
1781
  const walletHandler = useWalletHandler({
1615
1782
  getSession: () => {
@@ -1695,18 +1862,15 @@ function AomiRuntimeCore({
1695
1862
  [aomiClientRef, getUserState]
1696
1863
  );
1697
1864
  useEffect4(() => {
1698
- const unsubscribe = eventContext.subscribe(
1699
- "user_state_request",
1700
- () => {
1701
- var _a, _b, _c;
1702
- const session = (_b = (_a = sessionManagerRef.current) == null ? void 0 : _a.get(threadContext.currentThreadId)) != null ? _b : getSession(threadContext.currentThreadId);
1703
- eventContext.sendOutboundSystem({
1704
- type: "user_state_response",
1705
- sessionId: threadContext.currentThreadId,
1706
- payload: (_c = session.getUserState()) != null ? _c : getUserState()
1707
- });
1708
- }
1709
- );
1865
+ const unsubscribe = eventContext.subscribe("user_state_request", () => {
1866
+ var _a, _b, _c;
1867
+ const session = (_b = (_a = sessionManagerRef.current) == null ? void 0 : _a.get(threadContext.currentThreadId)) != null ? _b : getSession(threadContext.currentThreadId);
1868
+ eventContext.sendOutboundSystem({
1869
+ type: "user_state_response",
1870
+ sessionId: threadContext.currentThreadId,
1871
+ payload: (_c = session.getUserState()) != null ? _c : getUserState()
1872
+ });
1873
+ });
1710
1874
  return unsubscribe;
1711
1875
  }, [eventContext, threadContext.currentThreadId, getSession, getUserState]);
1712
1876
  useEffect4(() => {
@@ -1795,10 +1959,12 @@ function AomiRuntimeCore({
1795
1959
  () => buildThreadListAdapter({
1796
1960
  aomiClientRef,
1797
1961
  threadContext,
1798
- setIsRunning
1962
+ setIsRunning,
1963
+ getInitialControl: getPreferredThreadControl
1799
1964
  }),
1800
1965
  [
1801
1966
  aomiClientRef,
1967
+ getPreferredThreadControl,
1802
1968
  setIsRunning,
1803
1969
  threadContext,
1804
1970
  threadContext.currentThreadId,
@@ -1844,6 +2010,7 @@ function AomiRuntimeCore({
1844
2010
  (part) => part.type === "text"
1845
2011
  ).map((part) => part.text).join("\n");
1846
2012
  if (text) {
2013
+ await syncCurrentThreadControl();
1847
2014
  await orchestratorSendMessage(text, threadContext.currentThreadId);
1848
2015
  }
1849
2016
  },
@@ -1861,9 +2028,14 @@ function AomiRuntimeCore({
1861
2028
  const userContext = useUser();
1862
2029
  const sendMessage = useCallback7(
1863
2030
  async (text) => {
2031
+ await syncCurrentThreadControl();
1864
2032
  await orchestratorSendMessage(text, threadContext.currentThreadId);
1865
2033
  },
1866
- [orchestratorSendMessage, threadContext.currentThreadId]
2034
+ [
2035
+ orchestratorSendMessage,
2036
+ syncCurrentThreadControl,
2037
+ threadContext.currentThreadId
2038
+ ]
1867
2039
  );
1868
2040
  const cancelGeneration = useCallback7(() => {
1869
2041
  void orchestratorCancel(threadContext.currentThreadId);
@@ -1908,6 +2080,22 @@ function AomiRuntimeCore({
1908
2080
  },
1909
2081
  [threadContext.allThreadsMetadata, threadListAdapter]
1910
2082
  );
2083
+ const simulateBatchTransactions = useCallback7(
2084
+ async (transactions, options) => {
2085
+ var _a, _b;
2086
+ const session = (_b = (_a = sessionManagerRef.current) == null ? void 0 : _a.get(threadContext.currentThreadId)) != null ? _b : getSession(threadContext.currentThreadId);
2087
+ if (!session) {
2088
+ throw new Error("runtime_session_unavailable");
2089
+ }
2090
+ const response = await session.client.simulateBatch(
2091
+ session.sessionId,
2092
+ transactions,
2093
+ options
2094
+ );
2095
+ return response.result;
2096
+ },
2097
+ [getSession, threadContext.currentThreadId]
2098
+ );
1911
2099
  const aomiRuntimeApi = useMemo2(
1912
2100
  () => ({
1913
2101
  // User API
@@ -1942,6 +2130,7 @@ function AomiRuntimeCore({
1942
2130
  startWalletRequest: walletHandler.startRequest,
1943
2131
  resolveWalletRequest: walletHandler.resolveRequest,
1944
2132
  rejectWalletRequest: walletHandler.rejectRequest,
2133
+ simulateBatchTransactions,
1945
2134
  // Event API
1946
2135
  subscribe: eventContext.subscribe,
1947
2136
  sendSystemCommand: eventContext.sendOutboundSystem,
@@ -1964,6 +2153,7 @@ function AomiRuntimeCore({
1964
2153
  cancelGeneration,
1965
2154
  notificationContext,
1966
2155
  walletHandler,
2156
+ simulateBatchTransactions,
1967
2157
  eventContext
1968
2158
  ]
1969
2159
  );
@@ -2061,12 +2251,15 @@ export {
2061
2251
  ControlContextProvider,
2062
2252
  DISABLED_PROVIDER_STATE,
2063
2253
  EventContextProvider,
2254
+ MAX_AUTO_FEE_WEI,
2064
2255
  NotificationContextProvider,
2065
2256
  RuntimeUserStateProvider,
2066
2257
  SUPPORTED_CHAINS,
2067
2258
  ThreadContextProvider,
2068
2259
  UserContextProvider,
2069
2260
  aaModeFromExecutionKind,
2261
+ appendFeeCallToPayload,
2262
+ buildFeeAAWalletCall,
2070
2263
  cn,
2071
2264
  executeWalletCalls,
2072
2265
  formatAddress,
@@ -2074,7 +2267,9 @@ export {
2074
2267
  getNetworkName,
2075
2268
  hydrateTxPayloadFromUserState,
2076
2269
  initThreadControl,
2270
+ normalizeSimulatedFee,
2077
2271
  parseChainId,
2272
+ resolveAutoModel,
2078
2273
  toAAWalletCall,
2079
2274
  toAAWalletCalls,
2080
2275
  toViemSignTypedDataArgs,