Skip to content

Commit b0f76ab

Browse files
authored
fix(app): improve agent selection logic passing in configured models and variants correctly (anomalyco#16072)
1 parent adff319 commit b0f76ab

2 files changed

Lines changed: 24 additions & 11 deletions

File tree

packages/app/src/context/local.tsx

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({
3535

3636
const agent = (() => {
3737
const list = createMemo(() => sync.data.agent.filter((x) => x.mode !== "subagent" && !x.hidden))
38+
const models = useModels()
39+
3840
const [store, setStore] = createStore<{
3941
current?: string
4042
}>({
@@ -53,11 +55,17 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({
5355
setStore("current", undefined)
5456
return
5557
}
56-
if (name && available.some((x) => x.name === name)) {
57-
setStore("current", name)
58-
return
59-
}
60-
setStore("current", available[0].name)
58+
const match = name ? available.find((x) => x.name === name) : undefined
59+
const value = match ?? available[0]
60+
if (!value) return
61+
setStore("current", value.name)
62+
if (!value.model) return
63+
setModel({
64+
providerID: value.model.providerID,
65+
modelID: value.model.modelID,
66+
})
67+
if (value.variant)
68+
models.variant.set({ providerID: value.model.providerID, modelID: value.model.modelID }, value.variant)
6169
},
6270
move(direction: 1 | -1) {
6371
const available = list()
@@ -71,11 +79,13 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({
7179
const value = available[next]
7280
if (!value) return
7381
setStore("current", value.name)
74-
if (value.model)
75-
setModel({
76-
providerID: value.model.providerID,
77-
modelID: value.model.modelID,
78-
})
82+
if (!value.model) return
83+
setModel({
84+
providerID: value.model.providerID,
85+
modelID: value.model.modelID,
86+
})
87+
if (value.variant)
88+
models.variant.set({ providerID: value.model.providerID, modelID: value.model.modelID }, value.variant)
7989
},
8090
}
8191
})()

packages/app/src/pages/session.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,10 @@ export default function Page() {
416416
() => {
417417
const msg = lastUserMessage()
418418
if (!msg) return
419-
if (msg.agent) local.agent.set(msg.agent)
419+
if (msg.agent) {
420+
local.agent.set(msg.agent)
421+
if (local.agent.current()?.model) return
422+
}
420423
if (msg.model) local.model.set(msg.model)
421424
},
422425
),

0 commit comments

Comments
 (0)