Skip to content

Commit b7a7135

Browse files
opencode-agent[bot]arvsrnAarav Sareen
authored
feat(app): choose a model from a searchable list after connecting a provider (#66608)
Co-authored-by: arvsrn <96787824+arvsrn@users.noreply.github.com> Co-authored-by: Aarav Sareen <arvsrn@Aaravs-MacBook-Pro.local>
1 parent 8db8c7f commit b7a7135

11 files changed

Lines changed: 385 additions & 472 deletions

File tree

‎packages/app/e2e/regression/composer.spec.ts‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,16 +295,14 @@ test("the free usage limit opens the Go dialog once, swaps the composer for the
295295
await expect(view.editor).toHaveCount(0)
296296
await expect(page.getByText("Free usage limit reached.")).toHaveCount(0)
297297

298-
// Subscribe -> OpenCode sign-in -> the workspace's Go model -> Continue switches the model in the current session
298+
// Subscribe -> OpenCode sign-in -> choosing the workspace's Go model switches the model in the current session
299299
// without opening a new draft tab.
300300
await upsell.getByRole("button", { name: "Subscribe", exact: true }).click()
301301
const connect = page.getByRole("dialog", { name: "Connect OpenCode", exact: true })
302302
await connect.getByRole("button", { name: "OpenCode account", exact: true }).click()
303303
const connected = page.getByRole("dialog", { name: "Connected to OpenCode" })
304-
const go = connected.getByRole("radio", { name: "GLM-5 Go", exact: true })
305-
await go.click()
306-
await expect(go).toHaveAttribute("aria-checked", "true")
307-
await connected.getByRole("button", { name: "Continue", exact: true }).click()
304+
await connected.getByRole("combobox", { name: "Search OpenCode models", exact: true }).fill("glm")
305+
await connected.getByRole("option", { name: "GLM-5 Go", exact: true }).click()
308306
await expect(page.getByRole("dialog")).toHaveCount(0)
309307
await expectPath(page, sessionHref(sessionID))
310308
await expect(page.locator("[data-titlebar-tab-slot]")).toHaveCount(1)

‎packages/app/src/components-lab/focus-visibility.stories.tsx‎

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import "@/settings/settings.css"
88
import "@/settings/general/interface-mode.css"
99
import "@/shell/titlebar/pinned-area.css"
1010
import "@/settings/workspaces/project.css"
11-
import "@/providers/connect/models.css"
1211
import "@/shell/palette-menu.css"
1312
import "@/shell/search-list.css"
1413
import "@opencode/session-ui/sources/panel"
@@ -1717,45 +1716,6 @@ const surfaces: Surface[] = [
17171716
</div>
17181717
),
17191718
},
1720-
{
1721-
name: "First models after connecting: keyboard focus only changes the background",
1722-
failure: "Inconsistent",
1723-
target: ".connected-model-row",
1724-
keys: "Connect a provider for the first time, then Tab to a model.",
1725-
sizing: "Full-width radio rows in a list that clips them.",
1726-
source: "app/src/providers/connect/dialog.tsx (ConnectionModelList), models.css",
1727-
fix: "The row draws the shared ring inset (-2px) instead of the hover background, inside the list's clip. A checked row keeps its check, so selection stays distinct.",
1728-
render: () => (
1729-
<div data-component="first-provider-models" class="flex w-[360px] flex-col px-2">
1730-
<SettingsList>
1731-
<For each={["Claude Sonnet 4.5", "Claude Opus 4.6"]}>
1732-
{(name, index) => (
1733-
<div class="connected-model-row-shell">
1734-
<button
1735-
type="button"
1736-
role="radio"
1737-
data-component="settings-row"
1738-
aria-checked={index() === 0}
1739-
class="connected-model-row text-start"
1740-
>
1741-
<div data-slot="settings-row-copy">
1742-
<div data-slot="settings-row-title">
1743-
<span class="min-w-0 truncate">{name}</span>
1744-
</div>
1745-
</div>
1746-
<div data-slot="settings-row-control" class="size-4">
1747-
<Show when={index() === 0}>
1748-
<Icon name="check" class="shrink-0 text-v2-icon-icon-base" />
1749-
</Show>
1750-
</div>
1751-
</button>
1752-
</div>
1753-
)}
1754-
</For>
1755-
</SettingsList>
1756-
</div>
1757-
),
1758-
},
17591719
{
17601720
name: "Choose a model, no paid provider: rows and cards only change the background",
17611721
failure: "Inconsistent",
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import { Button } from "@opencode/ui/button"
2+
import { useDialog } from "@opencode/ui/context/dialog"
3+
import { Dialog } from "@opencode/ui/dialog"
4+
import { showToast } from "@/shell/notifications/toast"
5+
import { onMount } from "solid-js"
6+
import { ConnectedModelPicker } from "./connected-models"
7+
8+
type Groups = Parameters<typeof ConnectedModelPicker>[0]["groups"]
9+
10+
const models = (providerID: string, names: string[]) =>
11+
names.map((name) => ({ id: name.toLowerCase().replaceAll(" ", "-"), name, providerID }))
12+
13+
const google: Groups = [
14+
{
15+
provider: { id: "google", name: "Google" },
16+
models: models("google", [
17+
"Gemini 3 Pro Preview",
18+
"Gemini 3 Flash",
19+
"Gemini 2.5 Pro",
20+
"Gemini 2.5 Flash",
21+
"Gemini 2.5 Flash Lite",
22+
]),
23+
},
24+
]
25+
26+
const workspace: Groups = [
27+
{
28+
provider: { id: "opencode-go", name: "Acme / OpenCode Go" },
29+
models: models("opencode-go", ["GLM-5 Go", "Kimi K3", "DeepSeek V4 Pro", "Qwen 4 Coder"]),
30+
},
31+
{
32+
provider: { id: "opencode", name: "Acme / OpenCode Zen" },
33+
models: models("opencode", ["Claude Opus 5.5", "Claude Sonnet 5", "GPT-5.6", "Gemini 3 Pro", "Big Pickle"]),
34+
},
35+
]
36+
37+
// The connect dialog's models step around the real picker. Picking only shows a toast here.
38+
function PickerStory(props: { providerName: string; groups: Groups; workspace?: { prefix: string }; server?: string }) {
39+
const dialog = useDialog()
40+
41+
const open = () =>
42+
dialog.show(() => (
43+
<Dialog size="large" fit class="command-palette model-dialog [font-family:var(--v2-font-family-sans)]">
44+
<ConnectedModelPicker
45+
providerName={props.providerName}
46+
groups={props.groups}
47+
workspace={props.workspace}
48+
server={props.server}
49+
onSelect={(model) => {
50+
dialog.close()
51+
showToast({ variant: "success", icon: "circle-check", title: `Picked ${model.name}` })
52+
}}
53+
/>
54+
</Dialog>
55+
))
56+
57+
onMount(open)
58+
59+
return (
60+
<Button variant="neutral" onClick={open}>
61+
Open connected model picker
62+
</Button>
63+
)
64+
}
65+
66+
export default {
67+
title: "App/Dialogs/Connected model picker",
68+
id: "app-dialog-connected-model-picker",
69+
}
70+
71+
/** One provider: no section headers. Type to filter, Enter or click picks. */
72+
export const SingleProvider = { render: () => <PickerStory providerName="Google" groups={google} /> }
73+
74+
/** A Console workspace: one section per provider, named without the workspace prefix. */
75+
export const ConsoleWorkspace = {
76+
render: () => <PickerStory providerName="OpenCode" groups={workspace} workspace={{ prefix: "Acme / " }} />,
77+
}
78+
79+
/** A Console sign-in through a remote server names the server it is stored on. */
80+
export const ConsoleRemote = {
81+
render: () => (
82+
<PickerStory providerName="OpenCode" groups={workspace} workspace={{ prefix: "Acme / " }} server="Dev box" />
83+
),
84+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import { DialogBody, DialogTitle } from "@opencode/ui/dialog"
2+
import { SearchHighlight, SearchList } from "@opencode/ui/search-list"
3+
import { createMemo, createSignal, Show } from "solid-js"
4+
import { consoleProviderName } from "@/providers/catalog/console"
5+
import { matchesModelSearch } from "@/providers/models/search"
6+
import { useLanguage } from "@/runtime/i18n/language"
7+
import { modelKey } from "./controller"
8+
import { RemoteServerLabel } from "./remote"
9+
import "@/shell/commands/dialog.css"
10+
import "@/providers/models/select-dialog.css"
11+
12+
type ConnectionModel = { id: string; name: string; providerID: string }
13+
14+
type ConnectionGroup = { provider: { id: string; name: string }; models: ConnectionModel[] }
15+
16+
type Row = { id: string; model: ConnectionModel; provider: ConnectionGroup["provider"] }
17+
18+
/**
19+
* The model picker's search and rows, over only the models a new connection brought. It needs no composer: choosing a
20+
* model hands it back, and the connect dialog decides whether it goes to the caller's session or a new one.
21+
*/
22+
export function ConnectedModelPicker(props: {
23+
providerName: string
24+
/** The remote server a Console sign-in is stored on. */
25+
server?: string
26+
groups: ConnectionGroup[]
27+
/** A Console workspace's providers, whose section names drop the workspace prefix. */
28+
workspace?: { prefix: string }
29+
onSelect: (model: ConnectionModel) => void
30+
}) {
31+
const language = useLanguage()
32+
const [query, setQuery] = createSignal("")
33+
34+
const rows = createMemo(() => {
35+
const search = query().trim()
36+
37+
return props.groups.flatMap((group) =>
38+
group.models.flatMap((model): Row[] =>
39+
!search || matchesModelSearch(search, [model.name, model.id, group.provider.name])
40+
? [{ id: modelKey(model), model, provider: group.provider }]
41+
: [],
42+
),
43+
)
44+
})
45+
46+
const providerName = (provider: Row["provider"]) => {
47+
const workspace = props.workspace
48+
49+
return workspace ? consoleProviderName(workspace, provider.name) : provider.name
50+
}
51+
52+
return (
53+
<>
54+
<div class="sr-only">
55+
<DialogTitle>{language.t("provider.connect.models.title", { provider: props.providerName })}</DialogTitle>
56+
</div>
57+
<DialogBody class="command-palette-body">
58+
<SearchList
59+
topFade={false}
60+
// Without the picker's check column, the search icon, section headers and names share one inset.
61+
class={[
62+
"[&_[data-slot=text-input-v2-leading-icon]]:ms-0.5 [&_[data-slot=search-list-row]]:!ps-2.5 [&_[data-slot=search-list-header]]:!ps-4",
63+
props.groups.length > 1 ? "" : "[&_[data-slot=search-list-results]]:!pt-1.5",
64+
].join(" ")}
65+
query={query()}
66+
onQuery={setQuery}
67+
trailing={<Show when={props.server}>{(server) => <RemoteServerLabel server={server()} class="me-2" />}</Show>}
68+
placeholder={language.t("provider.connect.models.search", { provider: props.providerName })}
69+
label={language.t("provider.connect.models.list", { provider: props.providerName })}
70+
items={rows()}
71+
key={(row) => row.id}
72+
// One provider needs no header; a Console workspace or a multi-provider plan names each one.
73+
section={props.groups.length > 1 ? (row) => row.provider.id : undefined}
74+
header={
75+
props.groups.length > 1
76+
? (row) => (
77+
<span data-slot="model-dialog-header-label" class="flex min-w-0 items-center gap-1.5">
78+
<span class="min-w-0 truncate">{providerName(row.provider)}</span>
79+
</span>
80+
)
81+
: undefined
82+
}
83+
empty={language.t("dialog.model.empty")}
84+
onSelect={(row) => props.onSelect(row.model)}
85+
>
86+
{(row, attrs) => (
87+
<button type="button" {...attrs} data-option-key={row().id}>
88+
<span data-slot="model-dialog-name">
89+
<span class="min-w-0 truncate">
90+
<SearchHighlight text={row().model.name} />
91+
</span>
92+
</span>
93+
</button>
94+
)}
95+
</SearchList>
96+
</DialogBody>
97+
</>
98+
)
99+
}

‎packages/app/src/providers/connect/controller.ts‎

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,7 @@ export function createProviderDialogController(options: {
117117
provider() === CONSOLE_INTEGRATION ? consoleProviderGroup(connectionProviders()) : undefined,
118118
)
119119

120-
const firstModel = () => {
121-
const model = connectionGroups()[0]?.models[0]
122-
123-
return model ? modelKey(model) : undefined
124-
}
120+
const hasModels = () => connectionGroups().length > 0
125121

126122
const settler = createConsoleCatalogSettler({
127123
isLoaded: () => consoleCatalogLoaded(connectionProviders()),
@@ -228,7 +224,7 @@ export function createProviderDialogController(options: {
228224
session: effect.session,
229225
check: effect.check,
230226
hasProblem: accountsOf(CLAUDE_AGENT_INTEGRATION).problem,
231-
firstModel: firstModel(),
227+
hasModels: hasModels(),
232228
}),
233229
)
234230

@@ -277,7 +273,7 @@ export function createProviderDialogController(options: {
277273
const integrationID = input.provider
278274
const isConsole = integrationID === CONSOLE_INTEGRATION
279275

280-
const result = (event: ProviderConnectEvent, catalog?: { pending: boolean; firstModel: string | undefined }) =>
276+
const result = (event: ProviderConnectEvent, catalog?: { pending: boolean; hasModels: boolean }) =>
281277
dispatch({ type: "connect.result", session: input.session, provider: integrationID, event, catalog })
282278

283279
if (effect.type === "load") {
@@ -545,15 +541,12 @@ export function createProviderDialogController(options: {
545541
const refresh = async (
546542
effect: Extract<ProviderConnectEffect, { type: "refresh" }>,
547543
integrationID: string,
548-
result: (event: ProviderConnectEvent, catalog?: { pending: boolean; firstModel: string | undefined }) => void,
544+
result: (event: ProviderConnectEvent, catalog?: { pending: boolean; hasModels: boolean }) => void,
549545
) => {
550546
const refreshed = await sync()
551547

552548
if (integrationID !== CONSOLE_INTEGRATION)
553-
return result(
554-
{ type: "refresh.succeeded", attempt: effect.attempt },
555-
{ pending: false, firstModel: firstModel() },
556-
)
549+
return result({ type: "refresh.succeeded", attempt: effect.attempt }, { pending: false, hasModels: hasModels() })
557550

558551
if (!refreshed)
559552
return result({
@@ -568,7 +561,7 @@ export function createProviderDialogController(options: {
568561
if (outcome === "cancelled") return
569562
result(
570563
{ type: "refresh.succeeded", attempt: effect.attempt },
571-
{ pending: outcome === "timed-out", firstModel: firstModel() },
564+
{ pending: outcome === "timed-out", hasModels: hasModels() },
572565
)
573566
}
574567

@@ -608,12 +601,9 @@ export function createProviderDialogController(options: {
608601
})
609602

610603
createEffect(
611-
on(
612-
[claudePhase, () => !!claudeProblem(), () => connectionGroups().length > 0],
613-
([phase, hasProblem, hasModels]) => {
614-
if (phase) dispatch({ type: "claude.status.changed", hasProblem, hasModels })
615-
},
616-
),
604+
on([claudePhase, () => !!claudeProblem(), hasModels], ([phase, hasProblem, hasModels]) => {
605+
if (phase) dispatch({ type: "claude.status.changed", hasProblem, hasModels })
606+
}),
617607
)
618608

619609
onCleanup(() => dispatch({ type: "disposed" }))

0 commit comments

Comments
 (0)