Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix(tui): sort connect providers alphabetically
  • Loading branch information
robertDouglass committed Jun 5, 2026
commit 577fe02296a5ce00f50108c98fdf1ff94c534187
16 changes: 5 additions & 11 deletions packages/opencode/src/cli/cmd/tui/component/dialog-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,6 @@ import { isConsoleManagedProvider } from "@tui/util/provider-origin"
import { useConnected } from "./use-connected"
import { useBindings } from "../keymap"

const PROVIDER_PRIORITY: Record<string, number> = {
opencode: 0,
"opencode-go": 1,
openai: 2,
"github-copilot": 3,
anthropic: 4,
google: 5,
}

const CUSTOM_PROVIDER_OPTION_VALUE = "__opencode_custom_provider__"
const CUSTOM_PROVIDER_ID = /^[a-z0-9][a-z0-9-_]*$/

Expand All @@ -48,7 +39,10 @@ export function providerOptions(list: { id: string; name: string }[]): ProviderO
return [
...pipe(
list,
sortBy((x) => PROVIDER_PRIORITY[x.id] ?? 99),
sortBy(
(x) => x.name.toLowerCase(),
(x) => x.id,
),
map((provider) => ({
type: "provider" as const,
title: provider.name,
Expand All @@ -60,7 +54,7 @@ export function providerOptions(list: { id: string; name: string }[]): ProviderO
openai: "(ChatGPT Plus/Pro or API key)",
"opencode-go": "Low cost subscription for everyone",
}[provider.id],
category: provider.id in PROVIDER_PRIORITY ? "Popular" : "Providers",
category: "Providers",
})),
),
{
Expand Down
17 changes: 17 additions & 0 deletions packages/opencode/test/cli/cmd/tui/provider-options.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,23 @@ describe("providerOptions", () => {
expect(providerOptions([{ id: "mistral", name: "Mistral" }])[0]?.category).toBe("Providers")
})

test("sorts provider entries alphabetically and keeps Other last", () => {
const options = providerOptions([
{ id: "openai", name: "OpenAI" },
{ id: "custom-z", name: "OpenAI" },
{ id: "anthropic", name: "Anthropic" },
{ id: "google", name: "Google" },
])

expect(options.map((option) => option.value)).toEqual([
"anthropic",
"google",
"custom-z",
"openai",
"__opencode_custom_provider__",
])
})

test("does not collide with a configured provider named other", () => {
const values = providerOptions([{ id: "other", name: "Other Provider" }]).map((option) => option.value)
expect(new Set(values).size).toBe(values.length)
Expand Down
Loading