Просмотр исходного кода

Enhance auth command with environment variable display and add models command

🤖 Generated with [opencode](https://opencode.ai)

Co-Authored-By: opencode <[email protected]>
Dax Raad 8 месяцев назад
Родитель
Сommit
9751937894

+ 35 - 2
packages/opencode/src/cli/cmd/auth.ts

@@ -7,6 +7,9 @@ import open from "open"
 import { UI } from "../ui"
 import { ModelsDev } from "../../provider/models"
 import { map, pipe, sortBy, values } from "remeda"
+import path from "path"
+import os from "os"
+import { Global } from "../../global"
 
 export const AuthCommand = cmd({
   command: "auth",
@@ -26,16 +29,46 @@ export const AuthListCommand = cmd({
   describe: "list providers",
   async handler() {
     UI.empty()
-    prompts.intro("Credentials")
+    const authPath = path.join(Global.Path.data, "auth.json")
+    const homedir = os.homedir()
+    const displayPath = authPath.startsWith(homedir) 
+      ? authPath.replace(homedir, "~")
+      : authPath
+    prompts.intro(`Credentials ${UI.Style.TEXT_DIM}${displayPath}`)
     const results = await Auth.all().then((x) => Object.entries(x))
     const database = await ModelsDev.get()
 
     for (const [providerID, result] of results) {
       const name = database[providerID]?.name || providerID
-      prompts.log.info(`${name} ${UI.Style.TEXT_DIM}(${result.type})`)
+      prompts.log.info(`${name} ${UI.Style.TEXT_DIM}${result.type}`)
     }
 
     prompts.outro(`${results.length} credentials`)
+
+    // Environment variables section
+    const activeEnvVars: Array<{ provider: string, envVar: string }> = []
+    
+    for (const [providerID, provider] of Object.entries(database)) {
+      for (const envVar of provider.env) {
+        if (process.env[envVar]) {
+          activeEnvVars.push({ 
+            provider: provider.name || providerID, 
+            envVar 
+          })
+        }
+      }
+    }
+
+    if (activeEnvVars.length > 0) {
+      UI.empty()
+      prompts.intro("Environment")
+      
+      for (const { provider, envVar } of activeEnvVars) {
+        prompts.log.info(`${provider} ${UI.Style.TEXT_DIM}${envVar}`)
+      }
+      
+      prompts.outro(`${activeEnvVars.length} environment variables`)
+    }
   },
 })
 

+ 19 - 0
packages/opencode/src/cli/cmd/models.ts

@@ -0,0 +1,19 @@
+import { App } from "../../app/app"
+import { Provider } from "../../provider/provider"
+import { cmd } from "./cmd"
+
+export const ModelsCommand = cmd({
+  command: "models",
+  describe: "list all available models",
+  handler: async () => {
+    await App.provide({ cwd: process.cwd() }, async () => {
+      const providers = await Provider.list()
+      
+      for (const [providerID, provider] of Object.entries(providers)) {
+        for (const modelID of Object.keys(provider.info.models)) {
+          console.log(`${providerID}/${modelID}`)
+        }
+      }
+    })
+  },
+})

+ 2 - 0
packages/opencode/src/index.ts

@@ -14,6 +14,7 @@ import { ScrapCommand } from "./cli/cmd/scrap"
 import { Log } from "./util/log"
 import { AuthCommand, AuthLoginCommand } from "./cli/cmd/auth"
 import { UpgradeCommand } from "./cli/cmd/upgrade"
+import { ModelsCommand } from "./cli/cmd/models"
 import { Provider } from "./provider/provider"
 import { UI } from "./cli/ui"
 import { Installation } from "./installation"
@@ -140,6 +141,7 @@ const cli = yargs(hideBin(process.argv))
   .command(AuthCommand)
   .command(UpgradeCommand)
   .command(ServeCommand)
+  .command(ModelsCommand)
   .fail((msg) => {
     if (
       msg.startsWith("Unknown argument") ||