@@ -1948,15 +1948,15 @@ component
19481948 private function ensureBoxLang (){
19491949 if ( ! server .keyExists ( " boxlang" ) ) {
19501950 throw (
1951- type : " BoxLangRequiredException" ,
1952- message : " BoxLang is required for AI/MCP routing. toAi() and toMCP() are BoxLang-only features."
1951+ type : " BoxLangRequiredException" ,
1952+ message : " BoxLang is required for AI/MCP routing. toAi() and toMCP() are BoxLang-only features."
19531953 );
19541954 }
19551955
19561956 if ( ! getModuleList ().keyArray ().findNoCase ( " bxai" ) ) {
19571957 throw (
1958- type : " ModuleNotFoundException" ,
1959- message : " The BoxLang AI module (bxai) is required for AI/MCP routing. Install it via: box install bxai"
1958+ type : " ModuleNotFoundException" ,
1959+ message : " The BoxLang AI module (bxai) is required for AI/MCP routing. Install it via: box install bxai"
19601960 );
19611961 }
19621962 }
@@ -2008,10 +2008,10 @@ component
20082008 if (
20092009 ( ! isSimpleValue ( arguments .runnable ) && ! isObject ( arguments .runnable ) ) ||
20102010 isNumeric ( arguments .runnable )
2011- ) {
2011+ ) {
20122012 throw (
2013- type : " InvalidArgumentException" ,
2014- message : " The 'runnable' argument must be a WireBox ID string or an IAiRunnable instance"
2013+ type : " InvalidArgumentException" ,
2014+ message : " The 'runnable' argument must be a WireBox ID string or an IAiRunnable instance"
20152015 )
20162016 }
20172017
@@ -2043,15 +2043,20 @@ component
20432043 // =====================================================================================
20442044
20452045 // POST {base}/invoke — synchronous execution via run()
2046- var routeArgs = sharedArgs .copy ()
2046+ var routeArgs = sharedArgs
2047+ .copy ()
20472048 .append ( {
2048- " pattern" : " #basePath #/invoke" ,
2049- " name" : " #baseName #.invoke" ,
2050- " verbs" : " POST" ,
2051- " response" : ( event , rc , prc ) = > {
2049+ " pattern" : " #basePath #/invoke" ,
2050+ " name" : " #baseName #.invoke" ,
2051+ " verbs" : " POST" ,
2052+ " response" : ( event , rc , prc ) = > {
20522053 var runnableInstance = isSimpleValue ( capturedRunnable ) ? getInstance ( capturedRunnable ) : capturedRunnable
2053- var body = event .getHTTPContent ( json : true )
2054- var result = runnableInstance .run ( body .input ?: {}, body .params ?: {}, body .options ?: {} )
2054+ var body = event .getHTTPContent ( json : true )
2055+ var result = runnableInstance .run (
2056+ body .input ?: {},
2057+ body .params ?: {},
2058+ body .options ?: {}
2059+ )
20552060 return { " output" : result , " success" : true }
20562061 }
20572062 } )
@@ -2068,23 +2073,24 @@ component
20682073 // =====================================================================================
20692074
20702075 // POST {base}/stream — streaming via BoxLang SSE() BIF
2071- routeArgs = sharedArgs .copy ()
2076+ routeArgs = sharedArgs
2077+ .copy ()
20722078 .append ( {
2073- " pattern" : " #basePath #/stream" ,
2074- " name" : " #baseName #.stream" ,
2075- " verbs" : " POST" ,
2076- " response" : ( event , rc , prc ) = > {
2079+ " pattern" : " #basePath #/stream" ,
2080+ " name" : " #baseName #.stream" ,
2081+ " verbs" : " POST" ,
2082+ " response" : ( event , rc , prc ) = > {
20772083 var runnableInstance = isSimpleValue ( capturedRunnable ) ? getInstance ( capturedRunnable ) : capturedRunnable ;
2078- var body = event .getHTTPContent ( json : true );
2084+ var body = event .getHTTPContent ( json : true );
20792085 SSE (
2080- callback : ( emitter ) = > {
2086+ callback : ( emitter ) = > {
20812087 runnableInstance .stream (
20822088 ( chunk ) = > {
20832089 if ( ! emitter .isClosed () ) {
20842090 emitter .send ( chunk , " chunk" );
20852091 }
20862092 },
2087- body .input ?: {},
2093+ body .input ?: {},
20882094 body .params ?: {},
20892095 body .options ?: {}
20902096 );
@@ -2111,19 +2117,23 @@ component
21112117 // BATCH ROUTE
21122118 // =====================================================================================
21132119 // POST {base}/batch — run() for each item in inputs[]
2114- routeArgs = sharedArgs .copy ()
2120+ routeArgs = sharedArgs
2121+ .copy ()
21152122 .append ( {
2116- " pattern" : " #basePath #/batch" ,
2117- " name" : " #baseName #.batch" ,
2118- " verbs" : " POST" ,
2119- " response" : ( event , rc , prc ) = > {
2123+ " pattern" : " #basePath #/batch" ,
2124+ " name" : " #baseName #.batch" ,
2125+ " verbs" : " POST" ,
2126+ " response" : ( event , rc , prc ) = > {
21202127 var runnableInstance = isSimpleValue ( capturedRunnable ) ? getInstance ( capturedRunnable ) : capturedRunnable
2121- var body = event .getHTTPContent ( json : true )
2128+ var body = event .getHTTPContent ( json : true )
21222129 var params = body .params ?: {}
21232130 var options = body .options ?: {}
21242131 var outputs = ( body .inputs ?: [] ).map ( ( input ) = > {
21252132 try {
2126- return { output : runnableInstance .run ( input , params , options ), success : true };
2133+ return {
2134+ output : runnableInstance .run ( input , params , options ),
2135+ success : true
2136+ };
21272137 } catch ( any e ) {
21282138 return { error : e .message , success : false };
21292139 }
@@ -2143,22 +2153,39 @@ component
21432153 // INFO ROUTE
21442154 // =====================================================================================
21452155 // GET {base}/info — brief endpoint metadata
2146- routeArgs = sharedArgs .copy ()
2156+ routeArgs = sharedArgs
2157+ .copy ()
21472158 .append ( {
2148- " pattern" : " #basePath #/info" ,
2149- " name" : " #baseName #.info" ,
2150- " verbs" : " GET" ,
2151- " response" : ( event , rc , prc ) = > {
2159+ " pattern" : " #basePath #/info" ,
2160+ " name" : " #baseName #.info" ,
2161+ " verbs" : " GET" ,
2162+ " response" : ( event , rc , prc ) = > {
21522163 var runnableInstance = isSimpleValue ( capturedRunnable ) ? getInstance ( capturedRunnable ) : capturedRunnable
21532164 return {
21542165 " name" : runnableInstance .getName (),
21552166 " description" : runnableInstance ? .getDescription () ?: " " ,
21562167 " pattern" : basePath ,
2157- " endpoints" : [
2158- { " verb" : " POST" , " path" : basePath & " /invoke" , " description" : " Synchronous execution" },
2159- { " verb" : " POST" , " path" : basePath & " /stream" , " description" : " Streaming SSE execution" },
2160- { " verb" : " POST" , " path" : basePath & " /batch" , " description" : " Batch execution" },
2161- { " verb" : " GET" , " path" : basePath & " /info" , " description" : " Endpoint metadata" }
2168+ " endpoints" : [
2169+ {
2170+ " verb" : " POST" ,
2171+ " path" : basePath & " /invoke" ,
2172+ " description" : " Synchronous execution"
2173+ },
2174+ {
2175+ " verb" : " POST" ,
2176+ " path" : basePath & " /stream" ,
2177+ " description" : " Streaming SSE execution"
2178+ },
2179+ {
2180+ " verb" : " POST" ,
2181+ " path" : basePath & " /batch" ,
2182+ " description" : " Batch execution"
2183+ },
2184+ {
2185+ " verb" : " GET" ,
2186+ " path" : basePath & " /info" ,
2187+ " description" : " Endpoint metadata"
2188+ }
21622189 ]
21632190 }
21642191 }
@@ -2214,8 +2241,8 @@ component
22142241 // Validate argument
22152242 if ( ! len ( trim ( arguments .serverName ) ) && ! findNoCase ( " :mcpServer" , variables .this Route .pattern ) ) {
22162243 throw (
2217- type : " InvalidArgumentException" ,
2218- message : " The 'serverName' argument must be a non-empty string or the route pattern must contain the ':mcpServer' placeholder"
2244+ type : " InvalidArgumentException" ,
2245+ message : " The 'serverName' argument must be a non-empty string or the route pattern must contain the ':mcpServer' placeholder"
22192246 )
22202247 }
22212248
@@ -2226,7 +2253,7 @@ component
22262253
22272254 // Inline response closure: resolves the server name and delegates to MCPRequestProcessor
22282255 var mcpResponseClosure = ( event , rc , prc ) = > {
2229- var resolvedServerName = rc .keyExists ( " mcpServer" ) ? rc .mcpServer : serverName
2256+ var resolvedServerName = rc .keyExists ( " mcpServer" ) ? rc .mcpServer : serverName
22302257 return bxModules .bxai .models .mcp .MCPRequestProcessor :: processHttp ( resolvedServerName );
22312258 };
22322259
0 commit comments