GeezerVison is showing github.com — sync · nocksock/opencode@dfea678
File treeExpand file treeCollapse file tree Open diff view settings packages/opencode/src/cli/cmd/tui
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: .github/workflows/format.yml -1Lines changed: 0 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 18 | 18 | uses: actions/checkout@v4 | 19 | 19 | with: | 20 | 20 | token: ${{ secrets.GITHUB_TOKEN }} | 21 | | - ref: ${{ github.head_ref || github.ref }} | 22 | 21 |
| 23 | 22 | - name: Setup Bun | 24 | 23 | uses: ./.github/actions/setup-bun | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/cli/cmd/tui/app.tsx +16-9Lines changed: 16 additions & 9 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -11,7 +11,7 @@ import { DialogProvider as DialogProviderList } from "@tui/component/dialog-prov | 11 | 11 | import { SDKProvider, useSDK } from "@tui/context/sdk" | 12 | 12 | import { SyncProvider, useSync } from "@tui/context/sync" | 13 | 13 | import { LocalProvider, useLocal } from "@tui/context/local" | 14 | | -import { DialogModel } from "@tui/component/dialog-model" | | 14 | +import { DialogModel, useConnected } from "@tui/component/dialog-model" | 15 | 15 | import { DialogStatus } from "@tui/component/dialog-status" | 16 | 16 | import { DialogThemeList } from "@tui/component/dialog-theme-list" | 17 | 17 | import { DialogHelp } from "./ui/dialog-help" | @@ -233,18 +233,21 @@ function App() { | 233 | 233 | ), | 234 | 234 | ) | 235 | 235 |
| | 236 | + const connected = useConnected() | 236 | 237 | command.register(() => [ | 237 | 238 | { | 238 | 239 | title: "Switch session", | 239 | 240 | value: "session.list", | 240 | 241 | keybind: "session_list", | 241 | 242 | category: "Session", | | 243 | + suggested: sync.data.session.length > 0, | 242 | 244 | onSelect: () => { | 243 | 245 | dialog.replace(() => <DialogSessionList />) | 244 | 246 | }, | 245 | 247 | }, | 246 | 248 | { | 247 | 249 | title: "New session", | | 250 | + suggested: route.data.type === "session", | 248 | 251 | value: "session.new", | 249 | 252 | keybind: "session_new", | 250 | 253 | category: "Session", | @@ -263,13 +266,15 @@ function App() { | 263 | 266 | title: "Switch model", | 264 | 267 | value: "model.list", | 265 | 268 | keybind: "model_list", | | 269 | + suggested: true, | 266 | 270 | category: "Agent", | 267 | 271 | onSelect: () => { | 268 | 272 | dialog.replace(() => <DialogModel />) | 269 | 273 | }, | 270 | 274 | }, | 271 | 275 | { | 272 | 276 | title: "Model cycle", | | 277 | + disabled: true, | 273 | 278 | value: "model.cycle_recent", | 274 | 279 | keybind: "model_cycle_recent", | 275 | 280 | category: "Agent", | @@ -279,6 +284,7 @@ function App() { | 279 | 284 | }, | 280 | 285 | { | 281 | 286 | title: "Model cycle reverse", | | 287 | + disabled: true, | 282 | 288 | value: "model.cycle_recent_reverse", | 283 | 289 | keybind: "model_cycle_recent_reverse", | 284 | 290 | category: "Agent", | @@ -315,6 +321,15 @@ function App() { | 315 | 321 | local.agent.move(-1) | 316 | 322 | }, | 317 | 323 | }, | | 324 | + { | | 325 | + title: "Connect provider", | | 326 | + value: "provider.connect", | | 327 | + suggested: !connected(), | | 328 | + onSelect: () => { | | 329 | + dialog.replace(() => <DialogProviderList />) | | 330 | + }, | | 331 | + category: "Provider", | | 332 | + }, | 318 | 333 | { | 319 | 334 | title: "View status", | 320 | 335 | keybind: "status_view", | @@ -332,14 +347,6 @@ function App() { | 332 | 347 | }, | 333 | 348 | category: "System", | 334 | 349 | }, | 335 | | - { | 336 | | - title: "Connect provider", | 337 | | - value: "provider.connect", | 338 | | - onSelect: () => { | 339 | | - dialog.replace(() => <DialogProviderList />) | 340 | | - }, | 341 | | - category: "System", | 342 | | - }, | 343 | 350 | { | 344 | 351 | title: "Toggle appearance", | 345 | 352 | value: "theme.switch_mode", | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/cli/cmd/tui/component/dialog-command.tsx +18-7Lines changed: 18 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | 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" | 3 | 3 | import { | 4 | 4 | createContext, | 5 | 5 | createMemo, | @@ -18,6 +18,7 @@ const ctx = createContext<Context>() | 18 | 18 |
| 19 | 19 | export type CommandOption = DialogSelectOption & { | 20 | 20 | keybind?: keyof KeybindsConfig | | 21 | + suggested?: boolean | 21 | 22 | } | 22 | 23 |
| 23 | 24 | function init() { | @@ -26,7 +27,19 @@ function init() { | 26 | 27 | const dialog = useDialog() | 27 | 28 | const keybind = useKeybind() | 28 | 29 | 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 | + })) | 30 | 43 | }) | 31 | 44 | const suspended = () => suspendCount() > 0 | 32 | 45 |
| @@ -99,14 +112,12 @@ export function CommandProvider(props: ParentProps) { | 99 | 112 | } | 100 | 113 |
| 101 | 114 | function DialogCommand(props: { options: CommandOption[] }) { | 102 | | - const keybind = useKeybind() | | 115 | + let ref: DialogSelectRef<string> | 103 | 116 | return ( | 104 | 117 | <DialogSelect | | 118 | + ref={(r) => (ref = r)} | 105 | 119 | 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."))} | 110 | 121 | /> | 111 | 122 | ) | 112 | 123 | } |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/cli/cmd/tui/component/dialog-model.tsx +38-12Lines changed: 38 additions & 12 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -6,28 +6,41 @@ import { DialogSelect, type DialogSelectRef } from "@tui/ui/dialog-select" | 6 | 6 | import { useDialog } from "@tui/ui/dialog" | 7 | 7 | import { createDialogProviderOptions, DialogProvider } from "./dialog-provider" | 8 | 8 | import { Keybind } from "@/util/keybind" | 9 | | -import { iife } from "@/util/iife" | 10 | 9 |
| 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 }) { | 12 | 18 | const local = useLocal() | 13 | 19 | const sync = useSync() | 14 | 20 | const dialog = useDialog() | 15 | 21 | const [ref, setRef] = createSignal<DialogSelectRef<unknown>>() | 16 | 22 |
| 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() | 21 | 24 | const providers = createDialogProviderOptions() | 22 | 25 |
| | 26 | + const showExtra = createMemo(() => { | | 27 | + if (!connected()) return false | | 28 | + if (props.providerID) return false | | 29 | + return true | | 30 | + }) | | 31 | + | 23 | 32 | const options = createMemo(() => { | 24 | 33 | const query = ref()?.filter | 25 | | - const favorites = connected() ? local.model.favorite() : [] | | 34 | + const favorites = showExtra() ? local.model.favorite() : [] | 26 | 35 | const recents = local.model.recent() | 27 | 36 |
| 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 | + : [] | 31 | 44 |
| 32 | 45 | const favoriteOptions = !query | 33 | 46 | ? favorites.flatMap((item) => { | @@ -109,6 +122,7 @@ export function DialogModel() { | 109 | 122 | provider.models, | 110 | 123 | entries(), | 111 | 124 | filter(([_, info]) => info.status !== "deprecated"), | | 125 | + filter(([_, info]) => (props.providerID ? info.providerID === props.providerID : true)), | 112 | 126 | map(([model, info]) => { | 113 | 127 | const value = { | 114 | 128 | providerID: provider.id, | @@ -150,7 +164,10 @@ export function DialogModel() { | 150 | 164 | if (inRecents) return false | 151 | 165 | return true | 152 | 166 | }), | 153 | | - sortBy((x) => x.title), | | 167 | + sortBy( | | 168 | + (x) => x.footer !== "Free", | | 169 | + (x) => x.title, | | 170 | + ), | 154 | 171 | ), | 155 | 172 | ), | 156 | 173 | ), | @@ -169,6 +186,15 @@ export function DialogModel() { | 169 | 186 | ] | 170 | 187 | }) | 171 | 188 |
| | 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 | + | 172 | 198 | return ( | 173 | 199 | <DialogSelect | 174 | 200 | keybind={[ | @@ -189,7 +215,7 @@ export function DialogModel() { | 189 | 215 | }, | 190 | 216 | ]} | 191 | 217 | ref={setRef} | 192 | | - title="Select model" | | 218 | + title={title()} | 193 | 219 | current={local.model.current()} | 194 | 220 | options={options()} | 195 | 221 | /> | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/cli/cmd/tui/component/dialog-provider.tsx +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -124,7 +124,7 @@ function AutoMethod(props: AutoMethodProps) { | 124 | 124 | } | 125 | 125 | await sdk.client.instance.dispose() | 126 | 126 | await sync.bootstrap() | 127 | | - dialog.replace(() => <DialogModel />) | | 127 | + dialog.replace(() => <DialogModel providerID={props.providerID} />) | 128 | 128 | }) | 129 | 129 |
| 130 | 130 | return ( | @@ -172,7 +172,7 @@ function CodeMethod(props: CodeMethodProps) { | 172 | 172 | if (!error) { | 173 | 173 | await sdk.client.instance.dispose() | 174 | 174 | await sync.bootstrap() | 175 | | - dialog.replace(() => <DialogModel />) | | 175 | + dialog.replace(() => <DialogModel providerID={props.providerID} />) | 176 | 176 | return | 177 | 177 | } | 178 | 178 | setError(true) | @@ -229,7 +229,7 @@ function ApiMethod(props: ApiMethodProps) { | 229 | 229 | }) | 230 | 230 | await sdk.client.instance.dispose() | 231 | 231 | await sync.bootstrap() | 232 | | - dialog.replace(() => <DialogModel />) | | 232 | + dialog.replace(() => <DialogModel providerID={props.providerID} />) | 233 | 233 | }} | 234 | 234 | /> | 235 | 235 | ) | |
|