@aomi-labs/react 0.3.14 → 0.3.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/index.cjs +276 -106
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +23 -3
- package/dist/index.d.ts +23 -3
- package/dist/index.js +275 -106
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -73,6 +73,7 @@ __export(index_exports, {
|
|
|
73
73
|
initThreadControl: () => initThreadControl,
|
|
74
74
|
normalizeSimulatedFee: () => import_client8.normalizeSimulatedFee,
|
|
75
75
|
parseChainId: () => import_client8.parseChainId,
|
|
76
|
+
resolveAutoModel: () => resolveAutoModel,
|
|
76
77
|
toAAWalletCall: () => import_client8.toAAWalletCall,
|
|
77
78
|
toAAWalletCalls: () => import_client8.toAAWalletCalls,
|
|
78
79
|
toViemSignTypedDataArgs: () => import_client8.toViemSignTypedDataArgs,
|
|
@@ -126,6 +127,7 @@ var logThreadMetadataChange = (source, threadId, prev, next) => {
|
|
|
126
127
|
function initThreadControl() {
|
|
127
128
|
return {
|
|
128
129
|
model: null,
|
|
130
|
+
modelMode: "auto",
|
|
129
131
|
app: null,
|
|
130
132
|
controlDirty: false,
|
|
131
133
|
isProcessing: false
|
|
@@ -269,16 +271,36 @@ var ThreadStore = class {
|
|
|
269
271
|
}
|
|
270
272
|
};
|
|
271
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
|
+
|
|
272
291
|
// packages/react/src/contexts/control-context.tsx
|
|
273
292
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
274
293
|
var API_KEY_STORAGE_KEY = "aomi_api_key";
|
|
275
294
|
var CLIENT_ID_STORAGE_KEY = "aomi_client_id";
|
|
276
295
|
var PROVIDER_KEYS_STORAGE_KEY = "aomi_provider_keys";
|
|
296
|
+
var MODEL_SELECTION_STORAGE_KEY = "aomi_model_selection";
|
|
277
297
|
var PROVIDER_KEY_SECRET_PREFIX = "PROVIDER_KEY:";
|
|
278
298
|
function getOrCreateClientId() {
|
|
279
299
|
var _a, _b, _c, _d, _e;
|
|
280
300
|
try {
|
|
281
|
-
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
|
+
);
|
|
282
304
|
if (storedClientId && storedClientId.trim().length > 0) {
|
|
283
305
|
return storedClientId;
|
|
284
306
|
}
|
|
@@ -295,6 +317,49 @@ function getDefaultApp(apps) {
|
|
|
295
317
|
var _a;
|
|
296
318
|
return apps.includes("default") ? "default" : (_a = apps[0]) != null ? _a : null;
|
|
297
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
|
+
}
|
|
298
363
|
function resolveAuthorizedApp(app, authorizedApps, defaultApp) {
|
|
299
364
|
if (app && authorizedApps.includes(app)) {
|
|
300
365
|
return app;
|
|
@@ -414,13 +479,10 @@ function ControlContextProvider({
|
|
|
414
479
|
const fetchApps = async () => {
|
|
415
480
|
var _a2;
|
|
416
481
|
try {
|
|
417
|
-
const apps = await aomiClientRef.current.getApps(
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
apiKey: (_a2 = stateRef.current.apiKey) != null ? _a2 : void 0
|
|
422
|
-
}
|
|
423
|
-
);
|
|
482
|
+
const apps = await aomiClientRef.current.getApps(sessionIdRef.current, {
|
|
483
|
+
publicKey: publicKeyRef.current,
|
|
484
|
+
apiKey: (_a2 = stateRef.current.apiKey) != null ? _a2 : void 0
|
|
485
|
+
});
|
|
424
486
|
const defaultApp = getDefaultApp(apps);
|
|
425
487
|
setStateInternal((prev) => __spreadProps(__spreadValues({}, prev), {
|
|
426
488
|
authorizedApps: apps,
|
|
@@ -442,13 +504,10 @@ function ControlContextProvider({
|
|
|
442
504
|
const models = await aomiClientRef.current.getModels(
|
|
443
505
|
sessionIdRef.current
|
|
444
506
|
);
|
|
445
|
-
setStateInternal((prev) => {
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
defaultModel: (_a2 = models[0]) != null ? _a2 : null
|
|
450
|
-
});
|
|
451
|
-
});
|
|
507
|
+
setStateInternal((prev) => __spreadProps(__spreadValues({}, prev), {
|
|
508
|
+
availableModels: models,
|
|
509
|
+
defaultModel: resolveAutoModel(models)
|
|
510
|
+
}));
|
|
452
511
|
} catch (error) {
|
|
453
512
|
console.error("Failed to fetch models:", error);
|
|
454
513
|
}
|
|
@@ -531,26 +590,20 @@ function ControlContextProvider({
|
|
|
531
590
|
() => stateRef.current.providerKeys,
|
|
532
591
|
[]
|
|
533
592
|
);
|
|
534
|
-
const hasProviderKey = (0, import_react.useCallback)(
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
},
|
|
540
|
-
[]
|
|
541
|
-
);
|
|
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
|
+
}, []);
|
|
542
598
|
const getAvailableModels = (0, import_react.useCallback)(async () => {
|
|
543
599
|
try {
|
|
544
600
|
const models = await aomiClientRef.current.getModels(
|
|
545
601
|
sessionIdRef.current
|
|
546
602
|
);
|
|
547
|
-
setStateInternal((prev) => {
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
defaultModel: (_b2 = (_a2 = prev.defaultModel) != null ? _a2 : models[0]) != null ? _b2 : null
|
|
552
|
-
});
|
|
553
|
-
});
|
|
603
|
+
setStateInternal((prev) => __spreadProps(__spreadValues({}, prev), {
|
|
604
|
+
availableModels: models,
|
|
605
|
+
defaultModel: resolveAutoModel(models)
|
|
606
|
+
}));
|
|
554
607
|
return models;
|
|
555
608
|
} catch (error) {
|
|
556
609
|
console.error("Failed to fetch models:", error);
|
|
@@ -560,13 +613,10 @@ function ControlContextProvider({
|
|
|
560
613
|
const getAuthorizedApps = (0, import_react.useCallback)(async () => {
|
|
561
614
|
var _a2;
|
|
562
615
|
try {
|
|
563
|
-
const apps = await aomiClientRef.current.getApps(
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
apiKey: (_a2 = stateRef.current.apiKey) != null ? _a2 : void 0
|
|
568
|
-
}
|
|
569
|
-
);
|
|
616
|
+
const apps = await aomiClientRef.current.getApps(sessionIdRef.current, {
|
|
617
|
+
publicKey: publicKeyRef.current,
|
|
618
|
+
apiKey: (_a2 = stateRef.current.apiKey) != null ? _a2 : void 0
|
|
619
|
+
});
|
|
570
620
|
const defaultApp = getDefaultApp(apps);
|
|
571
621
|
setStateInternal((prev) => __spreadProps(__spreadValues({}, prev), {
|
|
572
622
|
authorizedApps: apps,
|
|
@@ -587,6 +637,19 @@ function ControlContextProvider({
|
|
|
587
637
|
const metadata = getThreadMetadataRef.current(sessionIdRef.current);
|
|
588
638
|
return (_a2 = metadata == null ? void 0 : metadata.control) != null ? _a2 : initThreadControl();
|
|
589
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
|
+
}, []);
|
|
590
653
|
const getCurrentThreadApp = (0, import_react.useCallback)(() => {
|
|
591
654
|
var _a2, _b2, _c;
|
|
592
655
|
const currentControl = (_b2 = (_a2 = getThreadMetadataRef.current(sessionIdRef.current)) == null ? void 0 : _a2.control) != null ? _b2 : initThreadControl();
|
|
@@ -596,60 +659,75 @@ function ControlContextProvider({
|
|
|
596
659
|
stateRef.current.defaultApp
|
|
597
660
|
)) != null ? _c : "default";
|
|
598
661
|
}, []);
|
|
599
|
-
const onModelSelect = (0, import_react.useCallback)(
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
});
|
|
624
|
-
updateThreadMetadataRef.current(threadId, {
|
|
625
|
-
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,
|
|
626
686
|
model,
|
|
627
687
|
app,
|
|
628
|
-
|
|
629
|
-
})
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
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", {
|
|
639
699
|
threadId,
|
|
640
700
|
model,
|
|
641
|
-
|
|
701
|
+
app,
|
|
702
|
+
backendUrl: aomiClientRef.current
|
|
703
|
+
});
|
|
704
|
+
try {
|
|
705
|
+
const result = await aomiClientRef.current.setModel(threadId, model, {
|
|
642
706
|
app,
|
|
643
|
-
apiKey: (
|
|
644
|
-
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
|
+
});
|
|
645
723
|
}
|
|
646
|
-
)
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
724
|
+
} catch (err) {
|
|
725
|
+
console.error("[control-context] setModel failed:", err);
|
|
726
|
+
throw err;
|
|
727
|
+
}
|
|
728
|
+
},
|
|
729
|
+
[]
|
|
730
|
+
);
|
|
653
731
|
const onAppSelect = (0, import_react.useCallback)((app) => {
|
|
654
732
|
var _a2, _b2;
|
|
655
733
|
const threadId = sessionIdRef.current;
|
|
@@ -661,9 +739,7 @@ function ControlContextProvider({
|
|
|
661
739
|
threadId
|
|
662
740
|
});
|
|
663
741
|
if (isProcessing2) {
|
|
664
|
-
console.warn(
|
|
665
|
-
"[control-context] Cannot switch app while processing"
|
|
666
|
-
);
|
|
742
|
+
console.warn("[control-context] Cannot switch app while processing");
|
|
667
743
|
return;
|
|
668
744
|
}
|
|
669
745
|
if (stateRef.current.authorizedApps.length > 0 && !stateRef.current.authorizedApps.includes(app)) {
|
|
@@ -695,6 +771,86 @@ function ControlContextProvider({
|
|
|
695
771
|
});
|
|
696
772
|
}
|
|
697
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
|
+
]);
|
|
698
854
|
const getControlState = (0, import_react.useCallback)(() => stateRef.current, []);
|
|
699
855
|
const onControlStateChange = (0, import_react.useCallback)(
|
|
700
856
|
(callback) => {
|
|
@@ -737,6 +893,8 @@ function ControlContextProvider({
|
|
|
737
893
|
onAppSelect,
|
|
738
894
|
isProcessing,
|
|
739
895
|
markControlSynced,
|
|
896
|
+
syncCurrentThreadControl,
|
|
897
|
+
getPreferredThreadControl,
|
|
740
898
|
getControlState,
|
|
741
899
|
onControlStateChange,
|
|
742
900
|
setState
|
|
@@ -1374,7 +1532,8 @@ function buildThreadLists(threadMetadata) {
|
|
|
1374
1532
|
function buildThreadListAdapter({
|
|
1375
1533
|
aomiClientRef,
|
|
1376
1534
|
threadContext,
|
|
1377
|
-
setIsRunning
|
|
1535
|
+
setIsRunning,
|
|
1536
|
+
getInitialControl = initThreadControl
|
|
1378
1537
|
}) {
|
|
1379
1538
|
const { regularThreads, archivedThreads } = buildThreadLists(
|
|
1380
1539
|
threadContext.allThreadsMetadata
|
|
@@ -1390,7 +1549,7 @@ function buildThreadListAdapter({
|
|
|
1390
1549
|
title: "New Chat",
|
|
1391
1550
|
status: "regular",
|
|
1392
1551
|
lastActiveAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1393
|
-
control:
|
|
1552
|
+
control: getInitialControl()
|
|
1394
1553
|
})
|
|
1395
1554
|
);
|
|
1396
1555
|
threadContext.setThreadMessages(threadId, []);
|
|
@@ -1462,7 +1621,7 @@ function buildThreadListAdapter({
|
|
|
1462
1621
|
title: "New Chat",
|
|
1463
1622
|
status: "regular",
|
|
1464
1623
|
lastActiveAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1465
|
-
control:
|
|
1624
|
+
control: getInitialControl()
|
|
1466
1625
|
})
|
|
1467
1626
|
);
|
|
1468
1627
|
threadContext.setThreadMessages(defaultId, []);
|
|
@@ -1624,7 +1783,12 @@ function AomiRuntimeCore({
|
|
|
1624
1783
|
const eventContext = useEventContext();
|
|
1625
1784
|
const notificationContext = useNotification();
|
|
1626
1785
|
const { user, onUserStateChange, getUserState } = useUser();
|
|
1627
|
-
const {
|
|
1786
|
+
const {
|
|
1787
|
+
getControlState,
|
|
1788
|
+
getCurrentThreadApp,
|
|
1789
|
+
getPreferredThreadControl,
|
|
1790
|
+
syncCurrentThreadControl
|
|
1791
|
+
} = useControl();
|
|
1628
1792
|
const sessionManagerRef = (0, import_react10.useRef)(null);
|
|
1629
1793
|
const walletHandler = useWalletHandler({
|
|
1630
1794
|
getSession: () => {
|
|
@@ -1710,18 +1874,15 @@ function AomiRuntimeCore({
|
|
|
1710
1874
|
[aomiClientRef, getUserState]
|
|
1711
1875
|
);
|
|
1712
1876
|
(0, import_react10.useEffect)(() => {
|
|
1713
|
-
const unsubscribe = eventContext.subscribe(
|
|
1714
|
-
|
|
1715
|
-
()
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
});
|
|
1723
|
-
}
|
|
1724
|
-
);
|
|
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
|
+
});
|
|
1725
1886
|
return unsubscribe;
|
|
1726
1887
|
}, [eventContext, threadContext.currentThreadId, getSession, getUserState]);
|
|
1727
1888
|
(0, import_react10.useEffect)(() => {
|
|
@@ -1810,10 +1971,12 @@ function AomiRuntimeCore({
|
|
|
1810
1971
|
() => buildThreadListAdapter({
|
|
1811
1972
|
aomiClientRef,
|
|
1812
1973
|
threadContext,
|
|
1813
|
-
setIsRunning
|
|
1974
|
+
setIsRunning,
|
|
1975
|
+
getInitialControl: getPreferredThreadControl
|
|
1814
1976
|
}),
|
|
1815
1977
|
[
|
|
1816
1978
|
aomiClientRef,
|
|
1979
|
+
getPreferredThreadControl,
|
|
1817
1980
|
setIsRunning,
|
|
1818
1981
|
threadContext,
|
|
1819
1982
|
threadContext.currentThreadId,
|
|
@@ -1859,6 +2022,7 @@ function AomiRuntimeCore({
|
|
|
1859
2022
|
(part) => part.type === "text"
|
|
1860
2023
|
).map((part) => part.text).join("\n");
|
|
1861
2024
|
if (text) {
|
|
2025
|
+
await syncCurrentThreadControl();
|
|
1862
2026
|
await orchestratorSendMessage(text, threadContext.currentThreadId);
|
|
1863
2027
|
}
|
|
1864
2028
|
},
|
|
@@ -1876,9 +2040,14 @@ function AomiRuntimeCore({
|
|
|
1876
2040
|
const userContext = useUser();
|
|
1877
2041
|
const sendMessage = (0, import_react10.useCallback)(
|
|
1878
2042
|
async (text) => {
|
|
2043
|
+
await syncCurrentThreadControl();
|
|
1879
2044
|
await orchestratorSendMessage(text, threadContext.currentThreadId);
|
|
1880
2045
|
},
|
|
1881
|
-
[
|
|
2046
|
+
[
|
|
2047
|
+
orchestratorSendMessage,
|
|
2048
|
+
syncCurrentThreadControl,
|
|
2049
|
+
threadContext.currentThreadId
|
|
2050
|
+
]
|
|
1882
2051
|
);
|
|
1883
2052
|
const cancelGeneration = (0, import_react10.useCallback)(() => {
|
|
1884
2053
|
void orchestratorCancel(threadContext.currentThreadId);
|
|
@@ -2113,6 +2282,7 @@ function useNotificationHandler({
|
|
|
2113
2282
|
initThreadControl,
|
|
2114
2283
|
normalizeSimulatedFee,
|
|
2115
2284
|
parseChainId,
|
|
2285
|
+
resolveAutoModel,
|
|
2116
2286
|
toAAWalletCall,
|
|
2117
2287
|
toAAWalletCalls,
|
|
2118
2288
|
toViemSignTypedDataArgs,
|