1- import { Hono } from "hono" ;
21import { cors } from "hono/cors" ;
32import { WebSocketServer } from "ws" ;
43import type { WebSocket } from "ws" ;
5- import { z } from "zod " ;
4+ import type * as xsschema from "xsschema " ;
65import { OpenAPIHono } from "@hono/zod-openapi" ;
76import { swaggerUI } from "@hono/swagger-ui" ;
87import type { AgentHistoryEntry } from "../agent/history" ;
@@ -25,7 +24,6 @@ import {
2524 type ErrorSchema ,
2625 type TextResponseSchema ,
2726 type ObjectResponseSchema ,
28- type AgentResponseSchema ,
2927 type TextRequestSchema ,
3028 type ObjectRequestSchema ,
3129} from "./api.routes" ;
@@ -164,7 +162,7 @@ app.openapi(getAgentsRoute, (c) => {
164162 } ) ;
165163
166164 // Define the exact success response type based on the route schema
167- type SuccessResponse = z . infer <
165+ type SuccessResponse = xsschema . Infer <
168166 ( typeof getAgentsRoute . responses ) [ 200 ] [ "content" ] [ "application/json" ] [ "schema" ]
169167 > ;
170168
@@ -177,7 +175,9 @@ app.openapi(getAgentsRoute, (c) => {
177175 } catch ( error ) {
178176 console . error ( "Failed to get agents:" , error ) ;
179177 return c . json (
180- { success : false , error : "Failed to retrieve agents" } satisfies z . infer < typeof ErrorSchema > ,
178+ { success : false , error : "Failed to retrieve agents" } satisfies xsschema . Infer <
179+ typeof ErrorSchema
180+ > ,
181181 500 ,
182182 ) ;
183183 }
@@ -259,22 +259,24 @@ app.openapi(textRoute, async (c) => {
259259
260260 if ( ! agent ) {
261261 return c . json (
262- { success : false , error : "Agent not found" } satisfies z . infer < typeof ErrorSchema > ,
262+ { success : false , error : "Agent not found" } satisfies xsschema . Infer < typeof ErrorSchema > ,
263263 404 ,
264264 ) ;
265265 }
266266
267267 try {
268- const { input, options = { } } = c . req . valid ( "json" ) as z . infer < typeof TextRequestSchema > ;
268+ const { input, options = { } } = c . req . valid ( "json" ) as xsschema . Infer < typeof TextRequestSchema > ;
269269
270270 const response = await agent . generateText ( input , options ) ;
271- return c . json ( { success : true , data : response } satisfies z . infer < typeof TextResponseSchema > ) ;
271+ return c . json ( { success : true , data : response } satisfies xsschema . Infer <
272+ typeof TextResponseSchema
273+ > ) ;
272274 } catch ( error ) {
273275 return c . json (
274276 {
275277 success : false ,
276278 error : error instanceof Error ? error . message : "Failed to generate text" ,
277- } satisfies z . infer < typeof ErrorSchema > ,
279+ } satisfies xsschema . Infer < typeof ErrorSchema > ,
278280 500 ,
279281 ) ;
280282 }
@@ -288,7 +290,7 @@ app.openapi(streamRoute, async (c) => {
288290
289291 if ( ! agent ) {
290292 return c . json (
291- { success : false , error : "Agent not found" } satisfies z . infer < typeof ErrorSchema > ,
293+ { success : false , error : "Agent not found" } satisfies xsschema . Infer < typeof ErrorSchema > ,
292294 404 ,
293295 ) ;
294296 }
@@ -300,7 +302,7 @@ app.openapi(streamRoute, async (c) => {
300302 maxTokens : 4000 ,
301303 temperature : 0.7 ,
302304 } ,
303- } = c . req . valid ( "json" ) as z . infer < typeof TextRequestSchema > ;
305+ } = c . req . valid ( "json" ) as xsschema . Infer < typeof TextRequestSchema > ;
304306
305307 const stream = new ReadableStream ( {
306308 async start ( controller ) {
@@ -367,7 +369,7 @@ app.openapi(streamRoute, async (c) => {
367369 {
368370 success : false ,
369371 error : error instanceof Error ? error . message : "Failed to initiate text stream" ,
370- } satisfies z . infer < typeof ErrorSchema > ,
372+ } satisfies xsschema . Infer < typeof ErrorSchema > ,
371373 500 ,
372374 ) ;
373375 }
@@ -381,7 +383,7 @@ app.openapi(objectRoute, async (c) => {
381383
382384 if ( ! agent ) {
383385 return c . json (
384- { success : false , error : "Agent not found" } satisfies z . infer < typeof ErrorSchema > ,
386+ { success : false , error : "Agent not found" } satisfies xsschema . Infer < typeof ErrorSchema > ,
385387 404 ,
386388 ) ;
387389 }
@@ -391,16 +393,19 @@ app.openapi(objectRoute, async (c) => {
391393 input,
392394 schema,
393395 options = { } ,
394- } = c . req . valid ( "json" ) as z . infer < typeof ObjectRequestSchema > ;
396+ } = c . req . valid ( "json" ) as xsschema . Infer < typeof ObjectRequestSchema > ;
395397
396398 const response = await agent . generateObject ( input , schema , options ) ;
397- return c . json ( { success : true , data : response } satisfies z . infer < typeof ObjectResponseSchema > ) ;
399+ return c . json (
400+ { success : true , data : response } satisfies xsschema . Infer < typeof ObjectResponseSchema > ,
401+ 200 ,
402+ ) ;
398403 } catch ( error ) {
399404 return c . json (
400405 {
401406 success : false ,
402407 error : error instanceof Error ? error . message : "Failed to generate object" ,
403- } satisfies z . infer < typeof ErrorSchema > ,
408+ } satisfies xsschema . Infer < typeof ErrorSchema > ,
404409 500 ,
405410 ) ;
406411 }
@@ -414,7 +419,7 @@ app.openapi(streamObjectRoute, async (c) => {
414419
415420 if ( ! agent ) {
416421 return c . json (
417- { success : false , error : "Agent not found" } satisfies z . infer < typeof ErrorSchema > ,
422+ { success : false , error : "Agent not found" } satisfies xsschema . Infer < typeof ErrorSchema > ,
418423 404 ,
419424 ) ;
420425 }
@@ -424,7 +429,7 @@ app.openapi(streamObjectRoute, async (c) => {
424429 input,
425430 schema,
426431 options = { } ,
427- } = c . req . valid ( "json" ) as z . infer < typeof ObjectRequestSchema > ;
432+ } = c . req . valid ( "json" ) as xsschema . Infer < typeof ObjectRequestSchema > ;
428433
429434 const agentStream = await agent . streamObject ( input , schema , options ) ;
430435
@@ -487,7 +492,7 @@ app.openapi(streamObjectRoute, async (c) => {
487492 {
488493 success : false ,
489494 error : error instanceof Error ? error . message : "Failed to initiate object stream" ,
490- } satisfies z . infer < typeof ErrorSchema > ,
495+ } satisfies xsschema . Infer < typeof ErrorSchema > ,
491496 500 ,
492497 ) ;
493498 }
0 commit comments