Skip to content

Commit dfea678

Browse files
committed
sync
1 parent 2ac8dd6 commit dfea678

File tree

9 files changed

+251
-170
lines changed

9 files changed

+251
-170
lines changed

.github/workflows/format.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ jobs:
1818
uses: actions/checkout@v4
1919
with:
2020
token: ${{ secrets.GITHUB_TOKEN }}
21-
ref: ${{ github.head_ref || github.ref }}
2221

2322
- name: Setup Bun
2423
uses: ./.github/actions/setup-bun

packages/opencode/src/cli/cmd/tui/app.tsx

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { DialogProvider as DialogProviderList } from "@tui/component/dialog-prov
1111
import { SDKProvider, useSDK } from "@tui/context/sdk"
1212
import { SyncProvider, useSync } from "@tui/context/sync"
1313
import { LocalProvider, useLocal } from "@tui/context/local"
14-
import { DialogModel } from "@tui/component/dialog-model"
14+
import { DialogModel, useConnected } from "@tui/component/dialog-model"
1515
import { DialogStatus } from "@tui/component/dialog-status"
1616
import { DialogThemeList } from "@tui/component/dialog-theme-list"
1717
import { DialogHelp } from "./ui/dialog-help"
@@ -233,18 +233,21 @@ function App() {
233233
),
234234
)
235235

236+
const connected = useConnected()
236237
command.register(() => [
237238
{
238239
title: "Switch session",
239240
value: "session.list",
240241
keybind: "session_list",
241242
category: "Session",
243+
suggested: sync.data.session.length > 0,
242244
onSelect: () => {
243245
dialog.replace(() => <DialogSessionList />)
244246
},
245247
},
246248
{
247249
title: "New session",
250+
suggested: route.data.type === "session",
248251
value: "session.new",
249252
keybind: "session_new",
250253
category: "Session",
@@ -263,13 +266,15 @@ function App() {
263266
title: "Switch model",
264267
value: "model.list",
265268
keybind: "model_list",
269+
suggested: true,
266270
category: "Agent",
267271
onSelect: () => {
268272
dialog.replace(() => <DialogModel />)
269273
},
270274
},
271275
{
272276
title: "Model cycle",
277+
disabled: true,
273278
value: "model.cycle_recent",
274279
keybind: "model_cycle_recent",
275280
category: "Agent",
@@ -279,6 +284,7 @@ function App() {
279284
},
280285
{
281286
title: "Model cycle reverse",
287+
disabled: true,
282288
value: "model.cycle_recent_reverse",
283289
keybind: "model_cycle_recent_reverse",
284290
category: "Agent",
@@ -315,6 +321,15 @@ function App() {
315321
local.agent.move(-1)
316322
},
317323
},
324+
{
325+
title: "Connect provider",
326+
value: "provider.connect",
327+
suggested: !connected(),
328+
onSelect: () => {
329+
dialog.replace(() => <DialogProviderList />)
330+
},
331+
category: "Provider",
332+
},
318333
{
319334
title: "View status",
320335
keybind: "status_view",
@@ -332,14 +347,6 @@ function App() {
332347
},
333348
category: "System",
334349
},
335-
{
336-
title: "Connect provider",
337-
value: "provider.connect",
338-
onSelect: () => {
339-
dialog.replace(() => <DialogProviderList />)
340-
},
341-
category: "System",
342-
},
343350
{
344351
title: "Toggle appearance",
345352
value: "theme.switch_mode",

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

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useDialog } from "@tui/ui/dialog"
2-
import { DialogSelect, type DialogSelectOption } from "@tui/ui/dialog-select"
2+
import { DialogSelect, type DialogSelectOption, type DialogSelectRef } from "@tui/ui/dialog-select"
33
import {
44
createContext,
55
createMemo,
@@ -18,6 +18,7 @@ const ctx = createContext<Context>()
1818

1919
export type CommandOption = DialogSelectOption & {
2020
keybind?: keyof KeybindsConfig
21+
suggested?: boolean
2122
}
2223

2324
function init() {
@@ -26,7 +27,19 @@ function init() {
2627
const dialog = useDialog()
2728
const keybind = useKeybind()
2829
const options = createMemo(() => {
29-
return registrations().flatMap((x) => x())
30+
const all = registrations().flatMap((x) => x())
31+
const suggested = all.filter((x) => x.suggested)
32+
return [
33+
...suggested.map((x) => ({
34+
...x,
35+
category: "Suggested",
36+
value: "suggested." + x.value,
37+
})),
38+
...all,
39+
].map((x) => ({
40+
...x,
41+
footer: x.keybind ? keybind.print(x.keybind) : undefined,
42+
}))
3043
})
3144
const suspended = () => suspendCount() > 0
3245

@@ -99,14 +112,12 @@ export function CommandProvider(props: ParentProps) {
99112
}
100113

101114
function DialogCommand(props: { options: CommandOption[] }) {
102-
const keybind = useKeybind()
115+
let ref: DialogSelectRef<string>
103116
return (
104117
<DialogSelect
118+
ref={(r) => (ref = r)}
105119
title="Commands"
106-
options={props.options.map((x) => ({
107-
...x,
108-
footer: x.keybind ? keybind.print(x.keybind) : undefined,
109-
}))}
120+
options={props.options.filter((x) => !ref?.filter || !x.value.startsWith("suggested."))}
110121
/>
111122
)
112123
}

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

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,41 @@ import { DialogSelect, type DialogSelectRef } from "@tui/ui/dialog-select"
66
import { useDialog } from "@tui/ui/dialog"
77
import { createDialogProviderOptions, DialogProvider } from "./dialog-provider"
88
import { Keybind } from "@/util/keybind"
9-
import { iife } from "@/util/iife"
109

11-
export function DialogModel() {
10+
export function useConnected() {
11+
const sync = useSync()
12+
return createMemo(() =>
13+
sync.data.provider.some((x) => x.id !== "opencode" || Object.values(x.models).some((y) => y.cost?.input !== 0)),
14+
)
15+
}
16+
17+
export function DialogModel(props: { providerID?: string }) {
1218
const local = useLocal()
1319
const sync = useSync()
1420
const dialog = useDialog()
1521
const [ref, setRef] = createSignal<DialogSelectRef<unknown>>()
1622

17-
const connected = createMemo(() =>
18-
sync.data.provider.some((x) => x.id !== "opencode" || Object.values(x.models).some((y) => y.cost?.input !== 0)),
19-
)
20-
23+
const connected = useConnected()
2124
const providers = createDialogProviderOptions()
2225

26+
const showExtra = createMemo(() => {
27+
if (!connected()) return false
28+
if (props.providerID) return false
29+
return true
30+
})
31+
2332
const options = createMemo(() => {
2433
const query = ref()?.filter
25-
const favorites = connected() ? local.model.favorite() : []
34+
const favorites = showExtra() ? local.model.favorite() : []
2635
const recents = local.model.recent()
2736

28-
const recentList = recents
29-
.filter((item) => !favorites.some((fav) => fav.providerID === item.providerID && fav.modelID === item.modelID))
30-
.slice(0, 5)
37+
const recentList = showExtra()
38+
? recents
39+
.filter(
40+
(item) => !favorites.some((fav) => fav.providerID === item.providerID && fav.modelID === item.modelID),
41+
)
42+
.slice(0, 5)
43+
: []
3144

3245
const favoriteOptions = !query
3346
? favorites.flatMap((item) => {
@@ -109,6 +122,7 @@ export function DialogModel() {
109122
provider.models,
110123
entries(),
111124
filter(([_, info]) => info.status !== "deprecated"),
125+
filter(([_, info]) => (props.providerID ? info.providerID === props.providerID : true)),
112126
map(([model, info]) => {
113127
const value = {
114128
providerID: provider.id,
@@ -150,7 +164,10 @@ export function DialogModel() {
150164
if (inRecents) return false
151165
return true
152166
}),
153-
sortBy((x) => x.title),
167+
sortBy(
168+
(x) => x.footer !== "Free",
169+
(x) => x.title,
170+
),
154171
),
155172
),
156173
),
@@ -169,6 +186,15 @@ export function DialogModel() {
169186
]
170187
})
171188

189+
const provider = createMemo(() =>
190+
props.providerID ? sync.data.provider.find((x) => x.id === props.providerID) : null,
191+
)
192+
193+
const title = createMemo(() => {
194+
if (provider()) return provider()!.name
195+
return "Select model"
196+
})
197+
172198
return (
173199
<DialogSelect
174200
keybind={[
@@ -189,7 +215,7 @@ export function DialogModel() {
189215
},
190216
]}
191217
ref={setRef}
192-
title="Select model"
218+
title={title()}
193219
current={local.model.current()}
194220
options={options()}
195221
/>

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ function AutoMethod(props: AutoMethodProps) {
124124
}
125125
await sdk.client.instance.dispose()
126126
await sync.bootstrap()
127-
dialog.replace(() => <DialogModel />)
127+
dialog.replace(() => <DialogModel providerID={props.providerID} />)
128128
})
129129

130130
return (
@@ -172,7 +172,7 @@ function CodeMethod(props: CodeMethodProps) {
172172
if (!error) {
173173
await sdk.client.instance.dispose()
174174
await sync.bootstrap()
175-
dialog.replace(() => <DialogModel />)
175+
dialog.replace(() => <DialogModel providerID={props.providerID} />)
176176
return
177177
}
178178
setError(true)
@@ -229,7 +229,7 @@ function ApiMethod(props: ApiMethodProps) {
229229
})
230230
await sdk.client.instance.dispose()
231231
await sync.bootstrap()
232-
dialog.replace(() => <DialogModel />)
232+
dialog.replace(() => <DialogModel providerID={props.providerID} />)
233233
}}
234234
/>
235235
)

0 commit comments

Comments
 (0)