Files
tf_code/packages/opencode/src/command/index.ts
Dax c1b4e1f19d Upgrade to Zod v4 (#2605)
Co-authored-by: GitHub Action <action@github.com>
2025-09-15 03:12:07 -04:00

47 lines
1.1 KiB
TypeScript

import z from "zod/v4"
import { Config } from "../config/config"
import { Instance } from "../project/instance"
export namespace Command {
export const Info = z
.object({
name: z.string(),
description: z.string().optional(),
agent: z.string().optional(),
model: z.string().optional(),
template: z.string(),
subtask: z.boolean().optional(),
})
.meta({
ref: "Command",
})
export type Info = z.infer<typeof Info>
const state = Instance.state(async () => {
const cfg = await Config.get()
const result: Record<string, Info> = {}
for (const [name, command] of Object.entries(cfg.command ?? {})) {
result[name] = {
name,
agent: command.agent,
model: command.model,
description: command.description,
template: command.template,
subtask: command.subtask,
}
}
return result
})
export async function get(name: string) {
return state().then((x) => x[name])
}
export async function list() {
return state().then((x) => Object.values(x))
}
}