11import { Hono , type Context } from "hono"
2+ import { describeRoute , resolver , validator } from "hono-openapi"
3+ import { z } from "zod"
24import { AsyncQueue } from "../util/queue"
35
4- interface Request {
5- path : string
6- body : any
7- }
6+ const TuiRequest = z . object ( {
7+ path : z . string ( ) ,
8+ body : z . any ( ) ,
9+ } )
10+
11+ type Request = z . infer < typeof TuiRequest >
812
913const request = new AsyncQueue < Request > ( )
1014const response = new AsyncQueue < any > ( )
@@ -19,12 +23,47 @@ export async function callTui(ctx: Context) {
1923}
2024
2125export const TuiRoute = new Hono ( )
22- . get ( "/next" , async ( c ) => {
23- const req = await request . next ( )
24- return c . json ( req )
25- } )
26- . post ( "/response" , async ( c ) => {
27- const body = await c . req . json ( )
28- response . push ( body )
29- return c . json ( true )
30- } )
26+ . get (
27+ "/next" ,
28+ describeRoute ( {
29+ description : "Get the next TUI request from the queue" ,
30+ operationId : "tui.control.next" ,
31+ responses : {
32+ 200 : {
33+ description : "Next TUI request" ,
34+ content : {
35+ "application/json" : {
36+ schema : resolver ( TuiRequest ) ,
37+ } ,
38+ } ,
39+ } ,
40+ } ,
41+ } ) ,
42+ async ( c ) => {
43+ const req = await request . next ( )
44+ return c . json ( req )
45+ } ,
46+ )
47+ . post (
48+ "/response" ,
49+ describeRoute ( {
50+ description : "Submit a response to the TUI request queue" ,
51+ operationId : "tui.control.response" ,
52+ responses : {
53+ 200 : {
54+ description : "Response submitted successfully" ,
55+ content : {
56+ "application/json" : {
57+ schema : resolver ( z . boolean ( ) ) ,
58+ } ,
59+ } ,
60+ } ,
61+ } ,
62+ } ) ,
63+ validator ( "json" , z . any ( ) ) ,
64+ async ( c ) => {
65+ const body = c . req . valid ( "json" )
66+ response . push ( body )
67+ return c . json ( true )
68+ } ,
69+ )
0 commit comments