From 9fb47bc855c5c30ab7602a34f9c6de0f9a8f091c Mon Sep 17 00:00:00 2001 From: Dax Raad Date: Fri, 13 Jun 2025 00:33:54 -0400 Subject: [PATCH] Enhance auth command with dynamic provider selection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add support for dynamically loading providers from ModelsDev - Prioritize anthropic as recommended provider - Add "other" provider option for manual entry - Include special handling for amazon-bedrock with AWS config guidance - Expand provider selection UI to show up to 8 providers 🤖 Generated with [OpenCode](https://opencode.ai) Co-Authored-By: OpenCode --- packages/opencode/src/cli/cmd/auth.ts | 52 ++++++++++++++++++++------- 1 file changed, 40 insertions(+), 12 deletions(-) diff --git a/packages/opencode/src/cli/cmd/auth.ts b/packages/opencode/src/cli/cmd/auth.ts index 00cbbd4e8..cb0ad004a 100644 --- a/packages/opencode/src/cli/cmd/auth.ts +++ b/packages/opencode/src/cli/cmd/auth.ts @@ -5,6 +5,7 @@ import * as prompts from "@clack/prompts" import open from "open" import { UI } from "../ui" import { ModelsDev } from "../../provider/models" +import { map, pipe, sort, sortBy, values } from "remeda" export const AuthCommand = cmd({ command: "auth", @@ -43,26 +44,53 @@ export const AuthLoginCommand = cmd({ async handler() { UI.empty() prompts.intro("Add credential") - const provider = await prompts.select({ + const providers = await ModelsDev.get() + const priority: Record = { + anthropic: 0, + openai: 1, + google: 2, + } + let provider = await prompts.select({ message: "Select provider", - maxItems: 2, + maxItems: 8, options: [ + ...pipe( + providers, + values(), + sortBy( + (x) => priority[x.id] ?? 99, + (x) => x.name ?? x.id, + ), + map((x) => ({ + label: x.name, + value: x.id, + hint: priority[x.id] === 0 ? "recommended" : undefined, + })), + ), { - label: "Anthropic", - value: "anthropic", - }, - { - label: "OpenAI", - value: "openai", - }, - { - label: "Google", - value: "google", + value: "other", + label: "Other", }, ], }) + if (prompts.isCancel(provider)) throw new UI.CancelledError() + if (provider === "other") { + provider = await prompts.text({ + message: "Enter provider - must match @ai-sdk/", + }) + if (prompts.isCancel(provider)) throw new UI.CancelledError() + } + + if (provider === "amazon-bedrock") { + prompts.log.info( + "Amazon bedrock can be configured with standard AWS environment variables like AWS_PROFILE or AWS_ACCESS_KEY_ID", + ) + prompts.outro("Done") + return + } + if (provider === "anthropic") { const method = await prompts.select({ message: "Login method",