@@ -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 );
@@ -2107,19 +2113,23 @@ component
21072113 // BATCH ROUTE
21082114 // =====================================================================================
21092115 // POST {base}/batch — run() for each item in inputs[]
2110- routeArgs = sharedArgs .copy ()
2116+ routeArgs = sharedArgs
2117+ .copy ()
21112118 .append ( {
2112- " pattern" : " #basePath #/batch" ,
2113- " name" : " #baseName #.batch" ,
2114- " verbs" : " POST" ,
2115- " response" : ( event , rc , prc ) = > {
2119+ " pattern" : " #basePath #/batch" ,
2120+ " name" : " #baseName #.batch" ,
2121+ " verbs" : " POST" ,
2122+ " response" : ( event , rc , prc ) = > {
21162123 var runnableInstance = isSimpleValue ( capturedRunnable ) ? getInstance ( capturedRunnable ) : capturedRunnable
2117- var body = event .getHTTPContent ( json : true )
2124+ var body = event .getHTTPContent ( json : true )
21182125 var params = body .params ?: {}
21192126 var options = body .options ?: {}
21202127 var outputs = ( body .inputs ?: [] ).map ( ( input ) = > {
21212128 try {
2122- return { output : runnableInstance .run ( input , params , options ), success : true };
2129+ return {
2130+ output : runnableInstance .run ( input , params , options ),
2131+ success : true
2132+ };
21232133 } catch ( any e ) {
21242134 return { error : e .message , success : false };
21252135 }
@@ -2139,22 +2149,39 @@ component
21392149 // INFO ROUTE
21402150 // =====================================================================================
21412151 // GET {base}/info — brief endpoint metadata
2142- routeArgs = sharedArgs .copy ()
2152+ routeArgs = sharedArgs
2153+ .copy ()
21432154 .append ( {
2144- " pattern" : " #basePath #/info" ,
2145- " name" : " #baseName #.info" ,
2146- " verbs" : " GET" ,
2147- " response" : ( event , rc , prc ) = > {
2155+ " pattern" : " #basePath #/info" ,
2156+ " name" : " #baseName #.info" ,
2157+ " verbs" : " GET" ,
2158+ " response" : ( event , rc , prc ) = > {
21482159 var runnableInstance = isSimpleValue ( capturedRunnable ) ? getInstance ( capturedRunnable ) : capturedRunnable
21492160 return {
21502161 " name" : runnableInstance .getName (),
21512162 " description" : runnableInstance ? .getDescription () ?: " " ,
21522163 " pattern" : basePath ,
2153- " endpoints" : [
2154- { " verb" : " POST" , " path" : basePath & " /invoke" , " description" : " Synchronous execution" },
2155- { " verb" : " POST" , " path" : basePath & " /stream" , " description" : " Streaming SSE execution" },
2156- { " verb" : " POST" , " path" : basePath & " /batch" , " description" : " Batch execution" },
2157- { " verb" : " GET" , " path" : basePath & " /info" , " description" : " Endpoint metadata" }
2164+ " endpoints" : [
2165+ {
2166+ " verb" : " POST" ,
2167+ " path" : basePath & " /invoke" ,
2168+ " description" : " Synchronous execution"
2169+ },
2170+ {
2171+ " verb" : " POST" ,
2172+ " path" : basePath & " /stream" ,
2173+ " description" : " Streaming SSE execution"
2174+ },
2175+ {
2176+ " verb" : " POST" ,
2177+ " path" : basePath & " /batch" ,
2178+ " description" : " Batch execution"
2179+ },
2180+ {
2181+ " verb" : " GET" ,
2182+ " path" : basePath & " /info" ,
2183+ " description" : " Endpoint metadata"
2184+ }
21582185 ]
21592186 }
21602187 }
@@ -2210,8 +2237,8 @@ component
22102237 // Validate argument
22112238 if ( ! len ( trim ( arguments .serverName ) ) ) {
22122239 throw (
2213- type : " InvalidArgumentException" ,
2214- message : " The 'serverName' argument must be a non-empty string"
2240+ type : " InvalidArgumentException" ,
2241+ message : " The 'serverName' argument must be a non-empty string"
22152242 )
22162243 }
22172244
@@ -2222,7 +2249,7 @@ component
22222249
22232250 // Inline response closure: resolves the server name and delegates to MCPRequestProcessor
22242251 var mcpResponseClosure = ( event , rc , prc ) = > {
2225- var resolvedServerName = rc .keyExists ( " mcpServer" ) ? rc .mcpServer : serverName
2252+ var resolvedServerName = rc .keyExists ( " mcpServer" ) ? rc .mcpServer : serverName
22262253 return bxModules .bxai .models .mcp .MCPRequestProcessor :: processHttp ( resolvedServerName );
22272254 };
22282255
0 commit comments