Skip to content

Commit 41b0d03

Browse files
authored
feat: add model variant selection dialog (anomalyco#19488)
1 parent 81eb6e6 commit 41b0d03

2 files changed

Lines changed: 43 additions & 4 deletions

File tree

packages/opencode/src/cli/cmd/tui/component/dialog-model.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { map, pipe, flatMap, entries, filter, sortBy, take } from "remeda"
55
import { DialogSelect } from "@tui/ui/dialog-select"
66
import { useDialog } from "@tui/ui/dialog"
77
import { createDialogProviderOptions, DialogProvider } from "./dialog-provider"
8+
import { DialogVariant } from "./dialog-variant"
89
import { useKeybind } from "../context/keybind"
910
import * as fuzzysort from "fuzzysort"
1011

@@ -50,8 +51,7 @@ export function DialogModel(props: { providerID?: string }) {
5051
disabled: provider.id === "opencode" && model.id.includes("-nano"),
5152
footer: model.cost?.input === 0 && provider.id === "opencode" ? "Free" : undefined,
5253
onSelect: () => {
53-
dialog.clear()
54-
local.model.set({ providerID: provider.id, modelID: model.id }, { recent: true })
54+
onSelect(provider.id, model.id)
5555
},
5656
},
5757
]
@@ -88,8 +88,7 @@ export function DialogModel(props: { providerID?: string }) {
8888
disabled: provider.id === "opencode" && model.includes("-nano"),
8989
footer: info.cost?.input === 0 && provider.id === "opencode" ? "Free" : undefined,
9090
onSelect() {
91-
dialog.clear()
92-
local.model.set({ providerID: provider.id, modelID: model }, { recent: true })
91+
onSelect(provider.id, model)
9392
},
9493
})),
9594
filter((x) => {
@@ -135,6 +134,15 @@ export function DialogModel(props: { providerID?: string }) {
135134

136135
const title = createMemo(() => provider()?.name ?? "Select model")
137136

137+
function onSelect(providerID: string, modelID: string) {
138+
local.model.set({ providerID, modelID }, { recent: true })
139+
if (local.model.variant.list().length > 0) {
140+
dialog.replace(() => <DialogVariant />)
141+
} else {
142+
dialog.clear()
143+
}
144+
}
145+
138146
return (
139147
<DialogSelect<ReturnType<typeof options>[number]["value"]>
140148
options={options()}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { createMemo } from "solid-js"
2+
import { useLocal } from "@tui/context/local"
3+
import { useSync } from "@tui/context/sync"
4+
import { DialogSelect } from "@tui/ui/dialog-select"
5+
import { useDialog } from "@tui/ui/dialog"
6+
7+
export function DialogVariant() {
8+
const local = useLocal()
9+
const dialog = useDialog()
10+
11+
const options = createMemo(() => {
12+
return local.model.variant.list().map((variant) => ({
13+
value: variant,
14+
title: variant,
15+
onSelect: () => {
16+
dialog.clear()
17+
local.model.variant.set(variant)
18+
},
19+
}))
20+
})
21+
22+
return (
23+
<DialogSelect<string>
24+
options={options()}
25+
title={"Select variant"}
26+
current={local.model.variant.current()}
27+
flat={true}
28+
skipFilter={true}
29+
/>
30+
)
31+
}

0 commit comments

Comments
 (0)