mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-03-31 06:12:26 +00:00
Co-authored-by: GitHub Action <action@github.com> Co-authored-by: Liang-Shih Lin <liangshihlin@proton.me> Co-authored-by: Dominik Engelhardt <dominikengelhardt@ymail.com> Co-authored-by: Jay V <air@live.ca> Co-authored-by: adamdottv <2363879+adamdottv@users.noreply.github.com>
49 lines
1.2 KiB
TypeScript
49 lines
1.2 KiB
TypeScript
import { Provider } from "../../provider/provider"
|
|
import { Server } from "../../server/server"
|
|
import { Share } from "../../share/share"
|
|
import { bootstrap } from "../bootstrap"
|
|
import { cmd } from "./cmd"
|
|
|
|
export const ServeCommand = cmd({
|
|
command: "serve",
|
|
builder: (yargs) =>
|
|
yargs
|
|
.option("port", {
|
|
alias: ["p"],
|
|
type: "number",
|
|
describe: "port to listen on",
|
|
default: 4096,
|
|
})
|
|
.option("hostname", {
|
|
alias: ["h"],
|
|
type: "string",
|
|
describe: "hostname to listen on",
|
|
default: "127.0.0.1",
|
|
}),
|
|
describe: "starts a headless opencode server",
|
|
handler: async (args) => {
|
|
const cwd = process.cwd()
|
|
await bootstrap({ cwd }, async () => {
|
|
const providers = await Provider.list()
|
|
if (Object.keys(providers).length === 0) {
|
|
return "needs_provider"
|
|
}
|
|
|
|
const hostname = args.hostname
|
|
const port = args.port
|
|
|
|
await Share.init()
|
|
const server = Server.listen({
|
|
port,
|
|
hostname,
|
|
})
|
|
|
|
console.log(`opencode server listening on http://${server.hostname}:${server.port}`)
|
|
|
|
await new Promise(() => {})
|
|
|
|
server.stop()
|
|
})
|
|
},
|
|
})
|