global.dispose

This commit is contained in:
Dax Raad
2025-12-10 22:22:00 -05:00
parent 530b75a92a
commit 13a77005f1
4 changed files with 75 additions and 9 deletions

View File

@@ -56,6 +56,7 @@ export namespace Server {
export const Event = {
Connected: BusEvent.define("server.connected", z.object({})),
Disposed: BusEvent.define("global.disposed", z.object({})),
}
const app = new Hono()
@@ -140,6 +141,35 @@ export namespace Server {
})
},
)
.post(
"/global/dispose",
describeRoute({
summary: "Dispose instance",
description: "Clean up and dispose all OpenCode instances, releasing all resources.",
operationId: "global.dispose",
responses: {
200: {
description: "Global disposed",
content: {
"application/json": {
schema: resolver(z.boolean()),
},
},
},
},
}),
async (c) => {
await Instance.disposeAll()
GlobalBus.emit("event", {
directory: "global",
payload: {
type: Event.Disposed.type,
properties: {},
},
})
return c.json(true)
},
)
.use(async (c, next) => {
const directory = c.req.query("directory") ?? c.req.header("x-opencode-directory") ?? process.cwd()
return Instance.provide({