Skip to content

Commit 673ba5d

Browse files
committed
fix(app): follow server default agent ordering
1 parent 2b890a2 commit 673ba5d

2 files changed

Lines changed: 8 additions & 34 deletions

File tree

‎packages/app/src/providers/models/selection.tsx‎

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,6 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({
8989
const models = useModels()
9090
const settings = useSettings()
9191
const configuredModel = useConfiguredModel()
92-
const configuredAgent = createMemo(() => {
93-
const entry = data.location.config
94-
.list({ directory: sdk().directory })
95-
?.findLast((entry) => entry.type === "document" && entry.info.default_agent !== undefined)
96-
return entry?.type === "document" ? entry.info.default_agent : undefined
97-
})
9892

9993
const id = createMemo(() => params.id || undefined)
10094

@@ -118,7 +112,7 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({
118112
draft?: State
119113
promoting?: State
120114
}>({
121-
current: undefined,
115+
current: list()[0]?.name,
122116
draft: undefined,
123117
})
124118

@@ -152,7 +146,7 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({
152146
}
153147

154148
if (items.some((item) => item.name === store.current)) return
155-
setStore("current", undefined)
149+
setStore("current", items[0]?.name)
156150
})
157151

158152
const scope = createMemo<State | undefined>(() => {
@@ -214,13 +208,7 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({
214208
list,
215209
visible: agentsVisible,
216210
current() {
217-
return pickAgent(
218-
scope()?.agent ??
219-
durable()?.agent ??
220-
(agentsVisible() ? store.current : undefined) ??
221-
configuredAgent() ??
222-
(agentsVisible() ? list()[0]?.name : "build"),
223-
)
211+
return pickAgent(scope()?.agent ?? durable()?.agent ?? (agentsVisible() ? store.current : list()[0]?.name))
224212
},
225213
set(name: string | undefined) {
226214
const item = pickAgent(name)

‎packages/app/test-browser/fixtures/model-selection.ts‎

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,7 @@ afterEach(() =>
9797
.forEach((dispose) => dispose()),
9898
)
9999

100-
function fixture(
101-
input: { session?: Commit; agents?: Agent[]; config?: ConfigModel; defaultAgent?: string; preferred?: string } = {},
102-
) {
100+
function fixture(input: { session?: Commit; agents?: Agent[]; config?: ConfigModel; preferred?: string } = {}) {
103101
const directory = `/selection-test/${crypto.randomUUID()}`
104102

105103
// SAFETY: fixture transitions clear the route as well as selecting session IDs.
@@ -110,7 +108,6 @@ function fixture(
110108
route: { id: "ses_a" as string | undefined },
111109
agents: input.agents ?? [agent("build"), agent("plan")],
112110
config: input.config,
113-
defaultAgent: input.defaultAgent,
114111
sessions: Object.fromEntries([["ses_a", input.session]]),
115112
providers: [{ id: "provider", name: "Provider", package: "@ai-sdk/test", activation: "enabled" }],
116113
models: ["a", "b", "c"].map((id) => ({
@@ -152,10 +149,7 @@ function fixture(
152149
location: {
153150
agent: { list: () => state.agents },
154151
config: {
155-
list: () =>
156-
state.configLoaded
157-
? [{ type: "document", info: { model: state.config, default_agent: state.defaultAgent } }]
158-
: undefined,
152+
list: () => (state.configLoaded ? [{ type: "document", info: { model: state.config } }] : undefined),
159153
sync: async () => {
160154
configLoads.push(state.connection)
161155
},
@@ -227,33 +221,25 @@ function selection(local: ReturnType<typeof useLocal>) {
227221
}
228222

229223
test("restores durable agents even when the agent selector is hidden", () => {
230-
const f = fixture({ session: durable("b", "high", "plan"), defaultAgent: "build" })
224+
const f = fixture({ session: durable("b", "high", "plan") })
231225
f.set("visible", false)
232226
const { local } = f.mount()
233227
expect(local.agent.visible()).toBe(false)
234228
expect(selection(local)).toEqual({ agent: "plan", model: "b", variant: "high" })
235229
})
236230

237-
test.each([true, false])("new sessions use the configured default with picker visibility %s", (visible) => {
238-
const f = fixture({ agents: [agent("build"), agent("plan"), agent("custom")], defaultAgent: "custom" })
231+
test.each([true, false])("new sessions use the server-selected default with picker visibility %s", (visible) => {
232+
const f = fixture({ agents: [agent("custom"), agent("build"), agent("plan")] })
239233
f.set("route", "id", undefined)
240234
f.set("visible", visible)
241235
const { local } = f.mount()
242236
expect(local.agent.current()?.name).toBe("custom")
243237
f.set("visible", !visible)
244238
expect(local.agent.current()?.name).toBe("custom")
245239
local.agent.set("plan")
246-
f.set("defaultAgent", "build")
247240
expect(local.agent.current()?.name).toBe("plan")
248241
})
249242

250-
test("unavailable configured default agents retain the build fallback", () => {
251-
const f = fixture({ defaultAgent: "missing" })
252-
f.set("route", "id", undefined)
253-
const { local } = f.mount()
254-
expect(local.agent.current()?.name).toBe("build")
255-
})
256-
257243
test("waits for initial configuration and reloads it after reconnecting", () => {
258244
const f = fixture({ config: "provider/b" })
259245
f.set("configLoaded", false)

0 commit comments

Comments
 (0)