mirror of
https://github.com/anomalyco/opencode.git
synced 2026-04-25 07:15:19 +00:00
OpenTUI is here (#2685)
This commit is contained in:
48
packages/opencode/src/cli/cmd/tui/worker.ts
Normal file
48
packages/opencode/src/cli/cmd/tui/worker.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { Installation } from "@/installation"
|
||||
import { Server } from "@/server/server"
|
||||
import { Log } from "@/util/log"
|
||||
import { Instance } from "@/project/instance"
|
||||
import { Rpc } from "@/util/rpc"
|
||||
|
||||
await Log.init({
|
||||
print: process.argv.includes("--print-logs"),
|
||||
dev: Installation.isLocal(),
|
||||
level: (() => {
|
||||
if (Installation.isLocal()) return "DEBUG"
|
||||
return "INFO"
|
||||
})(),
|
||||
})
|
||||
|
||||
process.on("unhandledRejection", (e) => {
|
||||
Log.Default.error("rejection", {
|
||||
e: e instanceof Error ? e.message : e,
|
||||
})
|
||||
})
|
||||
|
||||
process.on("uncaughtException", (e) => {
|
||||
Log.Default.error("exception", {
|
||||
e: e instanceof Error ? e.message : e,
|
||||
})
|
||||
})
|
||||
|
||||
let server: Bun.Server<undefined>
|
||||
export const rpc = {
|
||||
async server(input: { port: number; hostname: string }) {
|
||||
if (server) await server.stop(true)
|
||||
try {
|
||||
server = Server.listen(input)
|
||||
return {
|
||||
url: server.url.toString(),
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
throw e
|
||||
}
|
||||
},
|
||||
async shutdown() {
|
||||
await Instance.disposeAll()
|
||||
await server.stop(true)
|
||||
},
|
||||
}
|
||||
|
||||
Rpc.listen(rpc)
|
||||
Reference in New Issue
Block a user