mirror of
https://github.com/aljazceru/opencode.git
synced 2026-01-08 18:34:59 +01:00
web command
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { Server } from "../../server/server"
|
||||
import { UI } from "../ui"
|
||||
import { cmd } from "./cmd"
|
||||
|
||||
export const ServeCommand = cmd({
|
||||
@@ -24,7 +25,12 @@ export const ServeCommand = cmd({
|
||||
port,
|
||||
hostname,
|
||||
})
|
||||
console.log(`opencode server listening on http://${server.hostname}:${server.port}`)
|
||||
UI.println(
|
||||
UI.Style.TEXT_NORMAL_BOLD,
|
||||
"Web interface: ",
|
||||
UI.Style.TEXT_NORMAL,
|
||||
`https://desktop.dev.opencode.ai?url=${server.url}`,
|
||||
)
|
||||
await new Promise(() => {})
|
||||
await server.stop()
|
||||
},
|
||||
|
||||
@@ -178,12 +178,16 @@ function App() {
|
||||
|
||||
useKeyboard(async (evt) => {
|
||||
if (evt.meta && evt.name === "t") {
|
||||
renderer.toggleDebugOverlay()
|
||||
if (process.env.DEBUG) {
|
||||
renderer.toggleDebugOverlay()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if (evt.meta && evt.name === "d") {
|
||||
renderer.console.toggle()
|
||||
if (process.env.DEBUG) {
|
||||
renderer.console.toggle()
|
||||
}
|
||||
return
|
||||
}
|
||||
})
|
||||
|
||||
38
packages/opencode/src/cli/cmd/web.ts
Normal file
38
packages/opencode/src/cli/cmd/web.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { Server } from "../../server/server"
|
||||
import { UI } from "../ui"
|
||||
import { cmd } from "./cmd"
|
||||
import open from "open"
|
||||
|
||||
export const WebCommand = cmd({
|
||||
command: "web",
|
||||
builder: (yargs) =>
|
||||
yargs
|
||||
.option("port", {
|
||||
alias: ["p"],
|
||||
type: "number",
|
||||
describe: "port to listen on",
|
||||
default: 0,
|
||||
})
|
||||
.option("hostname", {
|
||||
type: "string",
|
||||
describe: "hostname to listen on",
|
||||
default: "127.0.0.1",
|
||||
}),
|
||||
describe: "starts a headless opencode server",
|
||||
handler: async (args) => {
|
||||
const hostname = args.hostname
|
||||
const port = args.port
|
||||
const server = Server.listen({
|
||||
port,
|
||||
hostname,
|
||||
})
|
||||
const url = `https://desktop.dev.opencode.ai?url=${server.url}`
|
||||
UI.empty()
|
||||
UI.println(UI.logo(" "))
|
||||
UI.empty()
|
||||
UI.println(UI.Style.TEXT_INFO_BOLD + " Web interface: ", UI.Style.TEXT_NORMAL, url)
|
||||
open(url).catch(() => {})
|
||||
await new Promise(() => {})
|
||||
await server.stop()
|
||||
},
|
||||
})
|
||||
@@ -22,6 +22,7 @@ import { TuiThreadCommand } from "./cli/cmd/tui/thread"
|
||||
import { TuiSpawnCommand } from "./cli/cmd/tui/spawn"
|
||||
import { AcpCommand } from "./cli/cmd/acp"
|
||||
import { EOL } from "os"
|
||||
import { WebCommand } from "./cli/cmd/web"
|
||||
|
||||
process.on("unhandledRejection", (e) => {
|
||||
Log.Default.error("rejection", {
|
||||
@@ -81,6 +82,7 @@ const cli = yargs(hideBin(process.argv))
|
||||
.command(AgentCommand)
|
||||
.command(UpgradeCommand)
|
||||
.command(ServeCommand)
|
||||
.command(WebCommand)
|
||||
.command(ModelsCommand)
|
||||
.command(StatsCommand)
|
||||
.command(ExportCommand)
|
||||
|
||||
Reference in New Issue
Block a user