Dax Raad 1 неделя назад
Родитель
Сommit
30d140008f

+ 4 - 0
packages/cli/src/commands/commands.ts

@@ -133,6 +133,10 @@ export const Commands = Spec.make(typeof OPENCODE_CLI_NAME === "string" ? OPENCO
       description: "Manage plugins",
       commands: [Spec.make("list", { description: "List active plugins" })],
     }),
+    Spec.make("models", {
+      description: "List all available models",
+      params: ServerParams,
+    }),
     Spec.make("mini", {
       description: "Start the minimal interactive interface",
       params: {

+ 26 - 0
packages/cli/src/commands/handlers/models.ts

@@ -0,0 +1,26 @@
+import { OpenCode } from "@opencode-ai/client"
+import { Service } from "@opencode-ai/client/effect/service"
+import { Effect, Option } from "effect"
+import { EOL } from "node:os"
+import { Commands } from "../commands"
+import { Runtime } from "../../framework/runtime"
+import { ServerConnection } from "../../services/server-connection"
+
+export default Runtime.handler(
+  Commands.commands.models,
+  Effect.fn("cli.models")(function* (input) {
+    const server = yield* ServerConnection.resolve({
+      server: Option.getOrUndefined(input.server),
+      standalone: input.standalone,
+    })
+    const client = OpenCode.make({
+      baseUrl: server.endpoint.url,
+      headers: Service.headers(server.endpoint),
+    })
+    const response = yield* Effect.promise(() => client.model.list({ location: { directory: process.cwd() } }))
+    const models = response.data
+      .map((model) => `${model.providerID}/${model.id}`)
+      .toSorted((a, b) => a.localeCompare(b))
+    if (models.length > 0) process.stdout.write(models.join(EOL) + EOL)
+  }),
+)

+ 1 - 0
packages/cli/src/index.ts

@@ -35,6 +35,7 @@ const Handlers = Runtime.handlers(Commands, {
   plugin: {
     list: () => import("./commands/handlers/plugin/list"),
   },
+  models: () => import("./commands/handlers/models"),
   mini: () => import("./commands/handlers/mini"),
   run: () => import("./commands/handlers/run"),
   pair: () => import("./commands/handlers/pair"),