Update implementation to make it cleaner
This commit is contained in:
parent
c61815232a
commit
8c3c08c50b
@ -1091,6 +1091,21 @@ def test_config_sync_switches_unpinned_session(monkeypatch):
|
|||||||
assert session["config_model_seen"] == ("new/model", "nous")
|
assert session["config_model_seen"] == ("new/model", "nous")
|
||||||
|
|
||||||
|
|
||||||
|
def test_config_sync_treats_auto_provider_as_unset(monkeypatch):
|
||||||
|
_patch_config_model(monkeypatch, "new/model", provider="auto")
|
||||||
|
session = _sync_test_session(config_model_seen=("old/model", ""))
|
||||||
|
calls = []
|
||||||
|
monkeypatch.setattr(
|
||||||
|
server,
|
||||||
|
"_apply_model_switch",
|
||||||
|
lambda sid, sess, raw, **kw: calls.append(raw),
|
||||||
|
)
|
||||||
|
|
||||||
|
server._sync_agent_model_with_config("sid", session)
|
||||||
|
|
||||||
|
assert calls == ["new/model"]
|
||||||
|
|
||||||
|
|
||||||
def test_config_sync_skips_session_pinned_by_model_command(monkeypatch):
|
def test_config_sync_skips_session_pinned_by_model_command(monkeypatch):
|
||||||
_patch_config_model(monkeypatch, "new/model")
|
_patch_config_model(monkeypatch, "new/model")
|
||||||
session = _sync_test_session(
|
session = _sync_test_session(
|
||||||
|
|||||||
@ -1424,6 +1424,8 @@ def _config_model_target() -> tuple[str, str]:
|
|||||||
provider = ""
|
provider = ""
|
||||||
if isinstance(cfg_model, dict):
|
if isinstance(cfg_model, dict):
|
||||||
provider = str(cfg_model.get("provider") or "").strip()
|
provider = str(cfg_model.get("provider") or "").strip()
|
||||||
|
if provider.lower() == "auto":
|
||||||
|
provider = ""
|
||||||
return model, provider
|
return model, provider
|
||||||
|
|
||||||
|
|
||||||
@ -2033,8 +2035,6 @@ def _sync_agent_model_with_config(sid: str, session: dict) -> None:
|
|||||||
session["config_model_seen"] = target
|
session["config_model_seen"] = target
|
||||||
if target == seen:
|
if target == seen:
|
||||||
return
|
return
|
||||||
if seen is None and target[0] == (getattr(agent, "model", "") or ""):
|
|
||||||
return
|
|
||||||
model, provider = target
|
model, provider = target
|
||||||
raw = f"{model} --provider {provider}" if provider else model
|
raw = f"{model} --provider {provider}" if provider else model
|
||||||
try:
|
try:
|
||||||
|
|||||||
@ -855,39 +855,34 @@ export default function ModelsPage() {
|
|||||||
});
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const load = useCallback(
|
const load = useCallback(() => {
|
||||||
(opts?: { silent?: boolean }) => {
|
setLoading(true);
|
||||||
if (!opts?.silent) {
|
setError(null);
|
||||||
setLoading(true);
|
Promise.all([
|
||||||
setError(null);
|
api.getModelsAnalytics(days),
|
||||||
}
|
api.getAuxiliaryModels().catch(() => null),
|
||||||
Promise.all([
|
])
|
||||||
api.getModelsAnalytics(days),
|
.then(([models, auxData]) => {
|
||||||
api.getAuxiliaryModels().catch(() => null),
|
setData(models);
|
||||||
])
|
setAux(auxData);
|
||||||
.then(([models, auxData]) => {
|
})
|
||||||
setData(models);
|
.catch((err) => setError(String(err)))
|
||||||
setAux(auxData);
|
.finally(() => setLoading(false));
|
||||||
})
|
}, [days]);
|
||||||
.catch((err) => {
|
|
||||||
if (!opts?.silent) setError(String(err));
|
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
if (!opts?.silent) setLoading(false);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
[days],
|
|
||||||
);
|
|
||||||
|
|
||||||
const onAssigned = useCallback(() => {
|
const refreshAux = useCallback(() => {
|
||||||
// Reload aux state after any assignment change.
|
|
||||||
api
|
api
|
||||||
.getAuxiliaryModels()
|
.getAuxiliaryModels()
|
||||||
.then(setAux)
|
.then(setAux)
|
||||||
.catch(() => {});
|
.catch(() => {});
|
||||||
setSaveKey((k) => k + 1);
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const onAssigned = useCallback(() => {
|
||||||
|
// Reload aux state after any assignment change.
|
||||||
|
refreshAux();
|
||||||
|
setSaveKey((k) => k + 1);
|
||||||
|
}, [refreshAux]);
|
||||||
|
|
||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
// Period selector + refresh both live in afterTitle so the controls
|
// Period selector + refresh both live in afterTitle so the controls
|
||||||
// sit immediately next to the page title instead of being pinned to
|
// sit immediately next to the page title instead of being pinned to
|
||||||
@ -912,7 +907,7 @@ export default function ModelsPage() {
|
|||||||
ghost
|
ghost
|
||||||
size="icon"
|
size="icon"
|
||||||
className="text-muted-foreground hover:text-foreground"
|
className="text-muted-foreground hover:text-foreground"
|
||||||
onClick={() => load()}
|
onClick={load}
|
||||||
disabled={loading}
|
disabled={loading}
|
||||||
aria-label={t.common.refresh}
|
aria-label={t.common.refresh}
|
||||||
>
|
>
|
||||||
@ -932,18 +927,22 @@ export default function ModelsPage() {
|
|||||||
}, [load]);
|
}, [load]);
|
||||||
|
|
||||||
// Model assignments can change outside this page (config editor, chat
|
// Model assignments can change outside this page (config editor, chat
|
||||||
// /model --global, CLI) — refetch silently when the page regains focus.
|
// /model --global, CLI), so refetch them when the page regains focus.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const refetch = () => {
|
let last = 0;
|
||||||
if (document.visibilityState === "visible") load({ silent: true });
|
const onFocus = () => {
|
||||||
|
if (document.visibilityState !== "visible") return;
|
||||||
|
if (Date.now() - last < 1000) return;
|
||||||
|
last = Date.now();
|
||||||
|
refreshAux();
|
||||||
};
|
};
|
||||||
window.addEventListener("focus", refetch);
|
window.addEventListener("focus", onFocus);
|
||||||
document.addEventListener("visibilitychange", refetch);
|
document.addEventListener("visibilitychange", onFocus);
|
||||||
return () => {
|
return () => {
|
||||||
window.removeEventListener("focus", refetch);
|
window.removeEventListener("focus", onFocus);
|
||||||
document.removeEventListener("visibilitychange", refetch);
|
document.removeEventListener("visibilitychange", onFocus);
|
||||||
};
|
};
|
||||||
}, [load]);
|
}, [refreshAux]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex min-w-0 max-w-full flex-col gap-6">
|
<div className="flex min-w-0 max-w-full flex-col gap-6">
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user