summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyler Gannon <[email protected]>2025-10-28 21:39:22 -0600
committerGitHub <[email protected]>2025-10-28 22:39:22 -0500
commit1e24514d61556e6681d1fc8738f51e6cc50f096f (patch)
tree4b5cc318d6715e46d096ee834e08fc2c3490e0ff
parent4b1c6300a0aff04bed3df3be6143681f6862eb61 (diff)
downloadopencode-1e24514d61556e6681d1fc8738f51e6cc50f096f.tar.gz
opencode-1e24514d61556e6681d1fc8738f51e6cc50f096f.zip
add OpenAPI annotations to tui.ts control endpoints (#3519)
-rw-r--r--packages/opencode/src/server/tui.ts65
1 files changed, 52 insertions, 13 deletions
diff --git a/packages/opencode/src/server/tui.ts b/packages/opencode/src/server/tui.ts
index 60ac5eef5..48c79ae0b 100644
--- a/packages/opencode/src/server/tui.ts
+++ b/packages/opencode/src/server/tui.ts
@@ -1,10 +1,14 @@
import { Hono, type Context } from "hono"
+import { describeRoute, resolver, validator } from "hono-openapi"
+import { z } from "zod"
import { AsyncQueue } from "../util/queue"
-interface Request {
- path: string
- body: any
-}
+const TuiRequest = z.object({
+ path: z.string(),
+ body: z.any(),
+})
+
+type Request = z.infer<typeof TuiRequest>
const request = new AsyncQueue<Request>()
const response = new AsyncQueue<any>()
@@ -19,12 +23,47 @@ export async function callTui(ctx: Context) {
}
export const TuiRoute = new Hono()
- .get("/next", async (c) => {
- const req = await request.next()
- return c.json(req)
- })
- .post("/response", async (c) => {
- const body = await c.req.json()
- response.push(body)
- return c.json(true)
- })
+ .get(
+ "/next",
+ describeRoute({
+ description: "Get the next TUI request from the queue",
+ operationId: "tui.control.next",
+ responses: {
+ 200: {
+ description: "Next TUI request",
+ content: {
+ "application/json": {
+ schema: resolver(TuiRequest),
+ },
+ },
+ },
+ },
+ }),
+ async (c) => {
+ const req = await request.next()
+ return c.json(req)
+ },
+ )
+ .post(
+ "/response",
+ describeRoute({
+ description: "Submit a response to the TUI request queue",
+ operationId: "tui.control.response",
+ responses: {
+ 200: {
+ description: "Response submitted successfully",
+ content: {
+ "application/json": {
+ schema: resolver(z.boolean()),
+ },
+ },
+ },
+ },
+ }),
+ validator("json", z.any()),
+ async (c) => {
+ const body = c.req.valid("json")
+ response.push(body)
+ return c.json(true)
+ },
+ )