mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-21 17:54:23 +01:00
add OpenAPI annotations to tui.ts control endpoints (#3519)
This commit is contained in:
@@ -1,10 +1,14 @@
|
|||||||
import { Hono, type Context } from "hono"
|
import { Hono, type Context } from "hono"
|
||||||
|
import { describeRoute, resolver, validator } from "hono-openapi"
|
||||||
|
import { z } from "zod"
|
||||||
import { AsyncQueue } from "../util/queue"
|
import { AsyncQueue } from "../util/queue"
|
||||||
|
|
||||||
interface Request {
|
const TuiRequest = z.object({
|
||||||
path: string
|
path: z.string(),
|
||||||
body: any
|
body: z.any(),
|
||||||
}
|
})
|
||||||
|
|
||||||
|
type Request = z.infer<typeof TuiRequest>
|
||||||
|
|
||||||
const request = new AsyncQueue<Request>()
|
const request = new AsyncQueue<Request>()
|
||||||
const response = new AsyncQueue<any>()
|
const response = new AsyncQueue<any>()
|
||||||
@@ -19,12 +23,47 @@ export async function callTui(ctx: Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const TuiRoute = new Hono()
|
export const TuiRoute = new Hono()
|
||||||
.get("/next", async (c) => {
|
.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()
|
const req = await request.next()
|
||||||
return c.json(req)
|
return c.json(req)
|
||||||
})
|
},
|
||||||
.post("/response", async (c) => {
|
)
|
||||||
const body = await c.req.json()
|
.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)
|
response.push(body)
|
||||||
return c.json(true)
|
return c.json(true)
|
||||||
})
|
},
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user