feat(cli): add models command

This commit is contained in:
Dax Raad 2026-08-06 01:10:34 -04:00
parent a38d44265b
commit 30d140008f
3 changed files with 31 additions and 0 deletions

View file

@ -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: {

View file

@ -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)
}),
)

View file

@ -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"),