@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.cjs +302 -106
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +36 -4
- package/dist/index.d.ts +36 -4
- package/dist/index.js +301 -106
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -55,12 +55,15 @@ __export(index_exports, {
|
|
|
55
55
|
ControlContextProvider: () => ControlContextProvider,
|
|
56
56
|
DISABLED_PROVIDER_STATE: () => import_client8.DISABLED_PROVIDER_STATE,
|
|
57
57
|
EventContextProvider: () => EventContextProvider,
|
|
58
|
+
MAX_AUTO_FEE_WEI: () => import_client8.MAX_AUTO_FEE_WEI,
|
|
58
59
|
NotificationContextProvider: () => NotificationContextProvider,
|
|
59
60
|
RuntimeUserStateProvider: () => RuntimeUserStateProvider,
|
|
60
61
|
SUPPORTED_CHAINS: () => SUPPORTED_CHAINS,
|
|
61
62
|
ThreadContextProvider: () => ThreadContextProvider,
|
|
62
63
|
UserContextProvider: () => UserContextProvider,
|
|
63
64
|
aaModeFromExecutionKind: () => import_client8.aaModeFromExecutionKind,
|
|
65
|
+
appendFeeCallToPayload: () => import_client8.appendFeeCallToPayload,
|
|
66
|
+
buildFeeAAWalletCall: () => import_client8.buildFeeAAWalletCall,
|
|
64
67
|
cn: () => cn,
|
|
65
68
|
executeWalletCalls: () => import_client8.executeWalletCalls,
|
|
66
69
|
formatAddress: () => formatAddress,
|
|
@@ -68,7 +71,9 @@ __export(index_exports, {
|
|
|
68
71
|
getNetworkName: () => getNetworkName,
|
|
69
72
|
hydrateTxPayloadFromUserState: () => import_client8.hydrateTxPayloadFromUserState,
|
|
70
73
|
initThreadControl: () => initThreadControl,
|
|
74
|
+
normalizeSimulatedFee: () => import_client8.normalizeSimulatedFee,
|
|
71
75
|
parseChainId: () => import_client8.parseChainId,
|
|
76
|
+
resolveAutoModel: () => resolveAutoModel,
|
|
72
77
|
toAAWalletCall: () => import_client8.toAAWalletCall,
|
|
73
78
|
toAAWalletCalls: () => import_client8.toAAWalletCalls,
|
|
74
79
|
toViemSignTypedDataArgs: () => import_client8.toViemSignTypedDataArgs,
|
|
@@ -122,6 +127,7 @@ var logThreadMetadataChange = (source, threadId, prev, next) => {
|
|
|
122
127
|
function initThreadControl() {
|
|
123
128
|
return {
|
|
124
129
|
model: null,
|
|
130
|
+
modelMode: "auto",
|
|
125
131
|
app: null,
|
|
126
132
|
controlDirty: false,
|
|
127
133
|
isProcessing: false
|
|
@@ -265,16 +271,36 @@ var ThreadStore = class {
|
|
|
265
271
|
}
|
|
266
272
|
};
|
|
267
273
|
|
|
274
|
+
// packages/react/src/utils/model-selection.ts
|
|
275
|
+
var PREFERRED_DEFAULT_MODEL_PATTERNS = [
|
|
276
|
+
/^claude-4\.5-haiku/i,
|
|
277
|
+
/^claude.*haiku/i,
|
|
278
|
+
/^gpt-4o-mini/i,
|
|
279
|
+
/^gemini.*flash/i
|
|
280
|
+
];
|
|
281
|
+
function resolveAutoModel(models) {
|
|
282
|
+
var _a;
|
|
283
|
+
if (models.length === 0) return null;
|
|
284
|
+
for (const pattern of PREFERRED_DEFAULT_MODEL_PATTERNS) {
|
|
285
|
+
const match = models.find((model) => pattern.test(model));
|
|
286
|
+
if (match) return match;
|
|
287
|
+
}
|
|
288
|
+
return (_a = models[0]) != null ? _a : null;
|
|
289
|
+
}
|
|
290
|
+
|
|
268
291
|
// packages/react/src/contexts/control-context.tsx
|
|
269
292
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
270
293
|
var API_KEY_STORAGE_KEY = "aomi_api_key";
|
|
271
294
|
var CLIENT_ID_STORAGE_KEY = "aomi_client_id";
|
|
272
295
|
var PROVIDER_KEYS_STORAGE_KEY = "aomi_provider_keys";
|
|
296
|
+
var MODEL_SELECTION_STORAGE_KEY = "aomi_model_selection";
|
|
273
297
|
var PROVIDER_KEY_SECRET_PREFIX = "PROVIDER_KEY:";
|
|
274
298
|
function getOrCreateClientId() {
|
|
275
299
|
var _a, _b, _c, _d, _e;
|
|
276
300
|
try {
|
|
277
|
-
const storedClientId = (_a = globalThis.localStorage) == null ? void 0 : _a.getItem(
|
|
301
|
+
const storedClientId = (_a = globalThis.localStorage) == null ? void 0 : _a.getItem(
|
|
302
|
+
CLIENT_ID_STORAGE_KEY
|
|
303
|
+
);
|
|
278
304
|
if (storedClientId && storedClientId.trim().length > 0) {
|
|
279
305
|
return storedClientId;
|
|
280
306
|
}
|
|
@@ -291,6 +317,49 @@ function getDefaultApp(apps) {
|
|
|
291
317
|
var _a;
|
|
292
318
|
return apps.includes("default") ? "default" : (_a = apps[0]) != null ? _a : null;
|
|
293
319
|
}
|
|
320
|
+
function readStoredModelPreference() {
|
|
321
|
+
var _a;
|
|
322
|
+
try {
|
|
323
|
+
const raw = (_a = globalThis.localStorage) == null ? void 0 : _a.getItem(MODEL_SELECTION_STORAGE_KEY);
|
|
324
|
+
if (!raw) return { mode: "auto", model: null };
|
|
325
|
+
const parsed = JSON.parse(raw);
|
|
326
|
+
return {
|
|
327
|
+
mode: parsed.mode === "manual" ? "manual" : "auto",
|
|
328
|
+
model: typeof parsed.model === "string" ? parsed.model : null
|
|
329
|
+
};
|
|
330
|
+
} catch (e) {
|
|
331
|
+
return { mode: "auto", model: null };
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
function writeStoredModelPreference(preference) {
|
|
335
|
+
var _a;
|
|
336
|
+
try {
|
|
337
|
+
(_a = globalThis.localStorage) == null ? void 0 : _a.setItem(
|
|
338
|
+
MODEL_SELECTION_STORAGE_KEY,
|
|
339
|
+
JSON.stringify(preference)
|
|
340
|
+
);
|
|
341
|
+
} catch (e) {
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
function resolvePreferredModelSelection(preference, models, defaultModel) {
|
|
345
|
+
var _a;
|
|
346
|
+
if (preference.mode === "manual" && preference.model && models.includes(preference.model)) {
|
|
347
|
+
return preference;
|
|
348
|
+
}
|
|
349
|
+
if (preference.mode === "auto") {
|
|
350
|
+
return {
|
|
351
|
+
mode: "auto",
|
|
352
|
+
model: (_a = resolveAutoModel(models)) != null ? _a : defaultModel
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
return {
|
|
356
|
+
mode: "auto",
|
|
357
|
+
model: defaultModel != null ? defaultModel : resolveAutoModel(models)
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
function getFallbackModel(models, defaultModel) {
|
|
361
|
+
return defaultModel != null ? defaultModel : resolveAutoModel(models);
|
|
362
|
+
}
|
|
294
363
|
function resolveAuthorizedApp(app, authorizedApps, defaultApp) {
|
|
295
364
|
if (app && authorizedApps.includes(app)) {
|
|
296
365
|
return app;
|
|
@@ -410,13 +479,10 @@ function ControlContextProvider({
|
|
|
410
479
|
const fetchApps = async () => {
|
|
411
480
|
var _a2;
|
|
412
481
|
try {
|
|
413
|
-
const apps = await aomiClientRef.current.getApps(
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
apiKey: (_a2 = stateRef.current.apiKey) != null ? _a2 : void 0
|
|
418
|
-
}
|
|
419
|
-
);
|
|
482
|
+
const apps = await aomiClientRef.current.getApps(sessionIdRef.current, {
|
|
483
|
+
publicKey: publicKeyRef.current,
|
|
484
|
+
apiKey: (_a2 = stateRef.current.apiKey) != null ? _a2 : void 0
|
|
485
|
+
});
|
|
420
486
|
const defaultApp = getDefaultApp(apps);
|
|
421
487
|
setStateInternal((prev) => __spreadProps(__spreadValues({}, prev), {
|
|
422
488
|
authorizedApps: apps,
|
|
@@ -438,13 +504,10 @@ function ControlContextProvider({
|
|
|
438
504
|
const models = await aomiClientRef.current.getModels(
|
|
439
505
|
sessionIdRef.current
|
|
440
506
|
);
|
|
441
|
-
setStateInternal((prev) => {
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
defaultModel: (_a2 = models[0]) != null ? _a2 : null
|
|
446
|
-
});
|
|
447
|
-
});
|
|
507
|
+
setStateInternal((prev) => __spreadProps(__spreadValues({}, prev), {
|
|
508
|
+
availableModels: models,
|
|
509
|
+
defaultModel: resolveAutoModel(models)
|
|
510
|
+
}));
|
|
448
511
|
} catch (error) {
|
|
449
512
|
console.error("Failed to fetch models:", error);
|
|
450
513
|
}
|
|
@@ -527,26 +590,20 @@ function ControlContextProvider({
|
|
|
527
590
|
() => stateRef.current.providerKeys,
|
|
528
591
|
[]
|
|
529
592
|
);
|
|
530
|
-
const hasProviderKey = (0, import_react.useCallback)(
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
},
|
|
536
|
-
[]
|
|
537
|
-
);
|
|
593
|
+
const hasProviderKey = (0, import_react.useCallback)((provider) => {
|
|
594
|
+
const keys = stateRef.current.providerKeys;
|
|
595
|
+
if (provider) return provider in keys;
|
|
596
|
+
return Object.keys(keys).length > 0;
|
|
597
|
+
}, []);
|
|
538
598
|
const getAvailableModels = (0, import_react.useCallback)(async () => {
|
|
539
599
|
try {
|
|
540
600
|
const models = await aomiClientRef.current.getModels(
|
|
541
601
|
sessionIdRef.current
|
|
542
602
|
);
|
|
543
|
-
setStateInternal((prev) => {
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
defaultModel: (_b2 = (_a2 = prev.defaultModel) != null ? _a2 : models[0]) != null ? _b2 : null
|
|
548
|
-
});
|
|
549
|
-
});
|
|
603
|
+
setStateInternal((prev) => __spreadProps(__spreadValues({}, prev), {
|
|
604
|
+
availableModels: models,
|
|
605
|
+
defaultModel: resolveAutoModel(models)
|
|
606
|
+
}));
|
|
550
607
|
return models;
|
|
551
608
|
} catch (error) {
|
|
552
609
|
console.error("Failed to fetch models:", error);
|
|
@@ -556,13 +613,10 @@ function ControlContextProvider({
|
|
|
556
613
|
const getAuthorizedApps = (0, import_react.useCallback)(async () => {
|
|
557
614
|
var _a2;
|
|
558
615
|
try {
|
|
559
|
-
const apps = await aomiClientRef.current.getApps(
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
apiKey: (_a2 = stateRef.current.apiKey) != null ? _a2 : void 0
|
|
564
|
-
}
|
|
565
|
-
);
|
|
616
|
+
const apps = await aomiClientRef.current.getApps(sessionIdRef.current, {
|
|
617
|
+
publicKey: publicKeyRef.current,
|
|
618
|
+
apiKey: (_a2 = stateRef.current.apiKey) != null ? _a2 : void 0
|
|
619
|
+
});
|
|
566
620
|
const defaultApp = getDefaultApp(apps);
|
|
567
621
|
setStateInternal((prev) => __spreadProps(__spreadValues({}, prev), {
|
|
568
622
|
authorizedApps: apps,
|
|
@@ -583,6 +637,19 @@ function ControlContextProvider({
|
|
|
583
637
|
const metadata = getThreadMetadataRef.current(sessionIdRef.current);
|
|
584
638
|
return (_a2 = metadata == null ? void 0 : metadata.control) != null ? _a2 : initThreadControl();
|
|
585
639
|
}, []);
|
|
640
|
+
const getPreferredThreadControl = (0, import_react.useCallback)(() => {
|
|
641
|
+
const preference = readStoredModelPreference();
|
|
642
|
+
const selection = resolvePreferredModelSelection(
|
|
643
|
+
preference,
|
|
644
|
+
stateRef.current.availableModels,
|
|
645
|
+
stateRef.current.defaultModel
|
|
646
|
+
);
|
|
647
|
+
return __spreadProps(__spreadValues({}, initThreadControl()), {
|
|
648
|
+
model: selection.model,
|
|
649
|
+
modelMode: selection.mode,
|
|
650
|
+
controlDirty: selection.model !== null
|
|
651
|
+
});
|
|
652
|
+
}, []);
|
|
586
653
|
const getCurrentThreadApp = (0, import_react.useCallback)(() => {
|
|
587
654
|
var _a2, _b2, _c;
|
|
588
655
|
const currentControl = (_b2 = (_a2 = getThreadMetadataRef.current(sessionIdRef.current)) == null ? void 0 : _a2.control) != null ? _b2 : initThreadControl();
|
|
@@ -592,60 +659,75 @@ function ControlContextProvider({
|
|
|
592
659
|
stateRef.current.defaultApp
|
|
593
660
|
)) != null ? _c : "default";
|
|
594
661
|
}, []);
|
|
595
|
-
const onModelSelect = (0, import_react.useCallback)(
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
});
|
|
620
|
-
updateThreadMetadataRef.current(threadId, {
|
|
621
|
-
control: __spreadProps(__spreadValues({}, currentControl), {
|
|
662
|
+
const onModelSelect = (0, import_react.useCallback)(
|
|
663
|
+
async (model, options) => {
|
|
664
|
+
var _a2, _b2, _c, _d, _e, _f, _g, _h;
|
|
665
|
+
const threadId = sessionIdRef.current;
|
|
666
|
+
const currentControl = (_b2 = (_a2 = getThreadMetadataRef.current(threadId)) == null ? void 0 : _a2.control) != null ? _b2 : initThreadControl();
|
|
667
|
+
const isProcessing2 = currentControl.isProcessing;
|
|
668
|
+
const modelMode = (_c = options == null ? void 0 : options.mode) != null ? _c : "manual";
|
|
669
|
+
console.log("[control-context] onModelSelect called", {
|
|
670
|
+
model,
|
|
671
|
+
modelMode,
|
|
672
|
+
isProcessing: isProcessing2,
|
|
673
|
+
threadId
|
|
674
|
+
});
|
|
675
|
+
if (isProcessing2) {
|
|
676
|
+
console.warn("[control-context] Cannot switch model while processing");
|
|
677
|
+
return;
|
|
678
|
+
}
|
|
679
|
+
const app = (_d = resolveAuthorizedApp(
|
|
680
|
+
currentControl.app,
|
|
681
|
+
stateRef.current.authorizedApps,
|
|
682
|
+
stateRef.current.defaultApp
|
|
683
|
+
)) != null ? _d : "default";
|
|
684
|
+
console.log("[control-context] onModelSelect updating metadata", {
|
|
685
|
+
threadId,
|
|
622
686
|
model,
|
|
623
687
|
app,
|
|
624
|
-
|
|
625
|
-
})
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
688
|
+
currentControl
|
|
689
|
+
});
|
|
690
|
+
updateThreadMetadataRef.current(threadId, {
|
|
691
|
+
control: __spreadProps(__spreadValues({}, currentControl), {
|
|
692
|
+
model,
|
|
693
|
+
modelMode,
|
|
694
|
+
app,
|
|
695
|
+
controlDirty: true
|
|
696
|
+
})
|
|
697
|
+
});
|
|
698
|
+
console.log("[control-context] onModelSelect calling backend setModel", {
|
|
635
699
|
threadId,
|
|
636
700
|
model,
|
|
637
|
-
|
|
701
|
+
app,
|
|
702
|
+
backendUrl: aomiClientRef.current
|
|
703
|
+
});
|
|
704
|
+
try {
|
|
705
|
+
const result = await aomiClientRef.current.setModel(threadId, model, {
|
|
638
706
|
app,
|
|
639
|
-
apiKey: (
|
|
640
|
-
clientId: (
|
|
707
|
+
apiKey: (_e = stateRef.current.apiKey) != null ? _e : void 0,
|
|
708
|
+
clientId: (_f = stateRef.current.clientId) != null ? _f : void 0
|
|
709
|
+
});
|
|
710
|
+
console.log("[control-context] onModelSelect backend result", result);
|
|
711
|
+
writeStoredModelPreference({
|
|
712
|
+
mode: modelMode,
|
|
713
|
+
model: modelMode === "manual" ? model : null
|
|
714
|
+
});
|
|
715
|
+
const latestControl = (_h = (_g = getThreadMetadataRef.current(threadId)) == null ? void 0 : _g.control) != null ? _h : currentControl;
|
|
716
|
+
if (latestControl.model === model && latestControl.app === app) {
|
|
717
|
+
updateThreadMetadataRef.current(threadId, {
|
|
718
|
+
control: __spreadProps(__spreadValues({}, latestControl), {
|
|
719
|
+
modelMode,
|
|
720
|
+
controlDirty: false
|
|
721
|
+
})
|
|
722
|
+
});
|
|
641
723
|
}
|
|
642
|
-
)
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
724
|
+
} catch (err) {
|
|
725
|
+
console.error("[control-context] setModel failed:", err);
|
|
726
|
+
throw err;
|
|
727
|
+
}
|
|
728
|
+
},
|
|
729
|
+
[]
|
|
730
|
+
);
|
|
649
731
|
const onAppSelect = (0, import_react.useCallback)((app) => {
|
|
650
732
|
var _a2, _b2;
|
|
651
733
|
const threadId = sessionIdRef.current;
|
|
@@ -657,9 +739,7 @@ function ControlContextProvider({
|
|
|
657
739
|
threadId
|
|
658
740
|
});
|
|
659
741
|
if (isProcessing2) {
|
|
660
|
-
console.warn(
|
|
661
|
-
"[control-context] Cannot switch app while processing"
|
|
662
|
-
);
|
|
742
|
+
console.warn("[control-context] Cannot switch app while processing");
|
|
663
743
|
return;
|
|
664
744
|
}
|
|
665
745
|
if (stateRef.current.authorizedApps.length > 0 && !stateRef.current.authorizedApps.includes(app)) {
|
|
@@ -691,6 +771,86 @@ function ControlContextProvider({
|
|
|
691
771
|
});
|
|
692
772
|
}
|
|
693
773
|
}, []);
|
|
774
|
+
const syncCurrentThreadControl = (0, import_react.useCallback)(async () => {
|
|
775
|
+
var _a2, _b2, _c, _d, _e, _f, _g;
|
|
776
|
+
const threadId = sessionIdRef.current;
|
|
777
|
+
const currentControl = (_b2 = (_a2 = getThreadMetadataRef.current(threadId)) == null ? void 0 : _a2.control) != null ? _b2 : initThreadControl();
|
|
778
|
+
if (!currentControl.controlDirty || currentControl.isProcessing || !currentControl.model) {
|
|
779
|
+
return;
|
|
780
|
+
}
|
|
781
|
+
const app = (_c = resolveAuthorizedApp(
|
|
782
|
+
currentControl.app,
|
|
783
|
+
stateRef.current.authorizedApps,
|
|
784
|
+
stateRef.current.defaultApp
|
|
785
|
+
)) != null ? _c : "default";
|
|
786
|
+
await aomiClientRef.current.setModel(threadId, currentControl.model, {
|
|
787
|
+
app,
|
|
788
|
+
apiKey: (_d = stateRef.current.apiKey) != null ? _d : void 0,
|
|
789
|
+
clientId: (_e = stateRef.current.clientId) != null ? _e : void 0
|
|
790
|
+
});
|
|
791
|
+
const latestControl = (_g = (_f = getThreadMetadataRef.current(threadId)) == null ? void 0 : _f.control) != null ? _g : currentControl;
|
|
792
|
+
if (latestControl.model === currentControl.model && latestControl.app === currentControl.app) {
|
|
793
|
+
updateThreadMetadataRef.current(threadId, {
|
|
794
|
+
control: __spreadProps(__spreadValues({}, latestControl), {
|
|
795
|
+
app,
|
|
796
|
+
controlDirty: false
|
|
797
|
+
})
|
|
798
|
+
});
|
|
799
|
+
}
|
|
800
|
+
}, []);
|
|
801
|
+
(0, import_react.useEffect)(() => {
|
|
802
|
+
var _a2;
|
|
803
|
+
const threadId = sessionIdRef.current;
|
|
804
|
+
const metadata = getThreadMetadataRef.current(threadId);
|
|
805
|
+
if (!metadata || metadata.control.isProcessing) return;
|
|
806
|
+
const currentControl = metadata.control;
|
|
807
|
+
let nextControl = null;
|
|
808
|
+
if (currentControl.model === null) {
|
|
809
|
+
const preferred = getPreferredThreadControl();
|
|
810
|
+
if (!preferred.model) return;
|
|
811
|
+
nextControl = __spreadProps(__spreadValues({}, currentControl), {
|
|
812
|
+
model: preferred.model,
|
|
813
|
+
modelMode: preferred.modelMode,
|
|
814
|
+
controlDirty: true
|
|
815
|
+
});
|
|
816
|
+
} else if (state.availableModels.length > 0) {
|
|
817
|
+
const currentMode = (_a2 = currentControl.modelMode) != null ? _a2 : "manual";
|
|
818
|
+
if (currentMode === "auto") {
|
|
819
|
+
const autoModel = getFallbackModel(
|
|
820
|
+
state.availableModels,
|
|
821
|
+
state.defaultModel
|
|
822
|
+
);
|
|
823
|
+
if (autoModel && currentControl.model !== autoModel) {
|
|
824
|
+
nextControl = __spreadProps(__spreadValues({}, currentControl), {
|
|
825
|
+
model: autoModel,
|
|
826
|
+
modelMode: "auto",
|
|
827
|
+
controlDirty: true
|
|
828
|
+
});
|
|
829
|
+
}
|
|
830
|
+
} else if (!state.availableModels.includes(currentControl.model)) {
|
|
831
|
+
const fallbackModel = getFallbackModel(
|
|
832
|
+
state.availableModels,
|
|
833
|
+
state.defaultModel
|
|
834
|
+
);
|
|
835
|
+
if (fallbackModel) {
|
|
836
|
+
nextControl = __spreadProps(__spreadValues({}, currentControl), {
|
|
837
|
+
model: fallbackModel,
|
|
838
|
+
modelMode: "auto",
|
|
839
|
+
controlDirty: true
|
|
840
|
+
});
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
if (!nextControl) return;
|
|
845
|
+
updateThreadMetadataRef.current(threadId, {
|
|
846
|
+
control: nextControl
|
|
847
|
+
});
|
|
848
|
+
}, [
|
|
849
|
+
getPreferredThreadControl,
|
|
850
|
+
sessionId,
|
|
851
|
+
state.availableModels,
|
|
852
|
+
state.defaultModel
|
|
853
|
+
]);
|
|
694
854
|
const getControlState = (0, import_react.useCallback)(() => stateRef.current, []);
|
|
695
855
|
const onControlStateChange = (0, import_react.useCallback)(
|
|
696
856
|
(callback) => {
|
|
@@ -733,6 +893,8 @@ function ControlContextProvider({
|
|
|
733
893
|
onAppSelect,
|
|
734
894
|
isProcessing,
|
|
735
895
|
markControlSynced,
|
|
896
|
+
syncCurrentThreadControl,
|
|
897
|
+
getPreferredThreadControl,
|
|
736
898
|
getControlState,
|
|
737
899
|
onControlStateChange,
|
|
738
900
|
setState
|
|
@@ -1370,7 +1532,8 @@ function buildThreadLists(threadMetadata) {
|
|
|
1370
1532
|
function buildThreadListAdapter({
|
|
1371
1533
|
aomiClientRef,
|
|
1372
1534
|
threadContext,
|
|
1373
|
-
setIsRunning
|
|
1535
|
+
setIsRunning,
|
|
1536
|
+
getInitialControl = initThreadControl
|
|
1374
1537
|
}) {
|
|
1375
1538
|
const { regularThreads, archivedThreads } = buildThreadLists(
|
|
1376
1539
|
threadContext.allThreadsMetadata
|
|
@@ -1386,7 +1549,7 @@ function buildThreadListAdapter({
|
|
|
1386
1549
|
title: "New Chat",
|
|
1387
1550
|
status: "regular",
|
|
1388
1551
|
lastActiveAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1389
|
-
control:
|
|
1552
|
+
control: getInitialControl()
|
|
1390
1553
|
})
|
|
1391
1554
|
);
|
|
1392
1555
|
threadContext.setThreadMessages(threadId, []);
|
|
@@ -1458,7 +1621,7 @@ function buildThreadListAdapter({
|
|
|
1458
1621
|
title: "New Chat",
|
|
1459
1622
|
status: "regular",
|
|
1460
1623
|
lastActiveAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1461
|
-
control:
|
|
1624
|
+
control: getInitialControl()
|
|
1462
1625
|
})
|
|
1463
1626
|
);
|
|
1464
1627
|
threadContext.setThreadMessages(defaultId, []);
|
|
@@ -1620,7 +1783,12 @@ function AomiRuntimeCore({
|
|
|
1620
1783
|
const eventContext = useEventContext();
|
|
1621
1784
|
const notificationContext = useNotification();
|
|
1622
1785
|
const { user, onUserStateChange, getUserState } = useUser();
|
|
1623
|
-
const {
|
|
1786
|
+
const {
|
|
1787
|
+
getControlState,
|
|
1788
|
+
getCurrentThreadApp,
|
|
1789
|
+
getPreferredThreadControl,
|
|
1790
|
+
syncCurrentThreadControl
|
|
1791
|
+
} = useControl();
|
|
1624
1792
|
const sessionManagerRef = (0, import_react10.useRef)(null);
|
|
1625
1793
|
const walletHandler = useWalletHandler({
|
|
1626
1794
|
getSession: () => {
|
|
@@ -1706,18 +1874,15 @@ function AomiRuntimeCore({
|
|
|
1706
1874
|
[aomiClientRef, getUserState]
|
|
1707
1875
|
);
|
|
1708
1876
|
(0, import_react10.useEffect)(() => {
|
|
1709
|
-
const unsubscribe = eventContext.subscribe(
|
|
1710
|
-
|
|
1711
|
-
()
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
});
|
|
1719
|
-
}
|
|
1720
|
-
);
|
|
1877
|
+
const unsubscribe = eventContext.subscribe("user_state_request", () => {
|
|
1878
|
+
var _a, _b, _c;
|
|
1879
|
+
const session = (_b = (_a = sessionManagerRef.current) == null ? void 0 : _a.get(threadContext.currentThreadId)) != null ? _b : getSession(threadContext.currentThreadId);
|
|
1880
|
+
eventContext.sendOutboundSystem({
|
|
1881
|
+
type: "user_state_response",
|
|
1882
|
+
sessionId: threadContext.currentThreadId,
|
|
1883
|
+
payload: (_c = session.getUserState()) != null ? _c : getUserState()
|
|
1884
|
+
});
|
|
1885
|
+
});
|
|
1721
1886
|
return unsubscribe;
|
|
1722
1887
|
}, [eventContext, threadContext.currentThreadId, getSession, getUserState]);
|
|
1723
1888
|
(0, import_react10.useEffect)(() => {
|
|
@@ -1806,10 +1971,12 @@ function AomiRuntimeCore({
|
|
|
1806
1971
|
() => buildThreadListAdapter({
|
|
1807
1972
|
aomiClientRef,
|
|
1808
1973
|
threadContext,
|
|
1809
|
-
setIsRunning
|
|
1974
|
+
setIsRunning,
|
|
1975
|
+
getInitialControl: getPreferredThreadControl
|
|
1810
1976
|
}),
|
|
1811
1977
|
[
|
|
1812
1978
|
aomiClientRef,
|
|
1979
|
+
getPreferredThreadControl,
|
|
1813
1980
|
setIsRunning,
|
|
1814
1981
|
threadContext,
|
|
1815
1982
|
threadContext.currentThreadId,
|
|
@@ -1855,6 +2022,7 @@ function AomiRuntimeCore({
|
|
|
1855
2022
|
(part) => part.type === "text"
|
|
1856
2023
|
).map((part) => part.text).join("\n");
|
|
1857
2024
|
if (text) {
|
|
2025
|
+
await syncCurrentThreadControl();
|
|
1858
2026
|
await orchestratorSendMessage(text, threadContext.currentThreadId);
|
|
1859
2027
|
}
|
|
1860
2028
|
},
|
|
@@ -1872,9 +2040,14 @@ function AomiRuntimeCore({
|
|
|
1872
2040
|
const userContext = useUser();
|
|
1873
2041
|
const sendMessage = (0, import_react10.useCallback)(
|
|
1874
2042
|
async (text) => {
|
|
2043
|
+
await syncCurrentThreadControl();
|
|
1875
2044
|
await orchestratorSendMessage(text, threadContext.currentThreadId);
|
|
1876
2045
|
},
|
|
1877
|
-
[
|
|
2046
|
+
[
|
|
2047
|
+
orchestratorSendMessage,
|
|
2048
|
+
syncCurrentThreadControl,
|
|
2049
|
+
threadContext.currentThreadId
|
|
2050
|
+
]
|
|
1878
2051
|
);
|
|
1879
2052
|
const cancelGeneration = (0, import_react10.useCallback)(() => {
|
|
1880
2053
|
void orchestratorCancel(threadContext.currentThreadId);
|
|
@@ -1919,6 +2092,22 @@ function AomiRuntimeCore({
|
|
|
1919
2092
|
},
|
|
1920
2093
|
[threadContext.allThreadsMetadata, threadListAdapter]
|
|
1921
2094
|
);
|
|
2095
|
+
const simulateBatchTransactions = (0, import_react10.useCallback)(
|
|
2096
|
+
async (transactions, options) => {
|
|
2097
|
+
var _a, _b;
|
|
2098
|
+
const session = (_b = (_a = sessionManagerRef.current) == null ? void 0 : _a.get(threadContext.currentThreadId)) != null ? _b : getSession(threadContext.currentThreadId);
|
|
2099
|
+
if (!session) {
|
|
2100
|
+
throw new Error("runtime_session_unavailable");
|
|
2101
|
+
}
|
|
2102
|
+
const response = await session.client.simulateBatch(
|
|
2103
|
+
session.sessionId,
|
|
2104
|
+
transactions,
|
|
2105
|
+
options
|
|
2106
|
+
);
|
|
2107
|
+
return response.result;
|
|
2108
|
+
},
|
|
2109
|
+
[getSession, threadContext.currentThreadId]
|
|
2110
|
+
);
|
|
1922
2111
|
const aomiRuntimeApi = (0, import_react10.useMemo)(
|
|
1923
2112
|
() => ({
|
|
1924
2113
|
// User API
|
|
@@ -1953,6 +2142,7 @@ function AomiRuntimeCore({
|
|
|
1953
2142
|
startWalletRequest: walletHandler.startRequest,
|
|
1954
2143
|
resolveWalletRequest: walletHandler.resolveRequest,
|
|
1955
2144
|
rejectWalletRequest: walletHandler.rejectRequest,
|
|
2145
|
+
simulateBatchTransactions,
|
|
1956
2146
|
// Event API
|
|
1957
2147
|
subscribe: eventContext.subscribe,
|
|
1958
2148
|
sendSystemCommand: eventContext.sendOutboundSystem,
|
|
@@ -1975,6 +2165,7 @@ function AomiRuntimeCore({
|
|
|
1975
2165
|
cancelGeneration,
|
|
1976
2166
|
notificationContext,
|
|
1977
2167
|
walletHandler,
|
|
2168
|
+
simulateBatchTransactions,
|
|
1978
2169
|
eventContext
|
|
1979
2170
|
]
|
|
1980
2171
|
);
|
|
@@ -2073,12 +2264,15 @@ function useNotificationHandler({
|
|
|
2073
2264
|
ControlContextProvider,
|
|
2074
2265
|
DISABLED_PROVIDER_STATE,
|
|
2075
2266
|
EventContextProvider,
|
|
2267
|
+
MAX_AUTO_FEE_WEI,
|
|
2076
2268
|
NotificationContextProvider,
|
|
2077
2269
|
RuntimeUserStateProvider,
|
|
2078
2270
|
SUPPORTED_CHAINS,
|
|
2079
2271
|
ThreadContextProvider,
|
|
2080
2272
|
UserContextProvider,
|
|
2081
2273
|
aaModeFromExecutionKind,
|
|
2274
|
+
appendFeeCallToPayload,
|
|
2275
|
+
buildFeeAAWalletCall,
|
|
2082
2276
|
cn,
|
|
2083
2277
|
executeWalletCalls,
|
|
2084
2278
|
formatAddress,
|
|
@@ -2086,7 +2280,9 @@ function useNotificationHandler({
|
|
|
2086
2280
|
getNetworkName,
|
|
2087
2281
|
hydrateTxPayloadFromUserState,
|
|
2088
2282
|
initThreadControl,
|
|
2283
|
+
normalizeSimulatedFee,
|
|
2089
2284
|
parseChainId,
|
|
2285
|
+
resolveAutoModel,
|
|
2090
2286
|
toAAWalletCall,
|
|
2091
2287
|
toAAWalletCalls,
|
|
2092
2288
|
toViemSignTypedDataArgs,
|