mirror of
https://github.com/anomalyco/opencode.git
synced 2026-08-08 20:33:18 +00:00
feat(cli): add models command
This commit is contained in:
parent
a38d44265b
commit
30d140008f
3 changed files with 31 additions and 0 deletions
|
|
@ -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
packages/cli/src/commands/handlers/models.ts
Normal file
26
packages/cli/src/commands/handlers/models.ts
Normal 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)
|
||||
}),
|
||||
)
|
||||
|
|
@ -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"),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue