@@ -28,6 +28,8 @@ const requireAuth = process.env.NEMOCLAW_FAKE_OPENAI_REQUIRE_AUTH === "1";
2828const requireAuthModels = process . env . NEMOCLAW_FAKE_OPENAI_REQUIRE_AUTH_MODELS === "1" ;
2929const chatContent = process . env . NEMOCLAW_FAKE_OPENAI_CHAT_CONTENT || "ok" ;
3030const responseText = process . env . NEMOCLAW_FAKE_OPENAI_RESPONSE_TEXT || chatContent ;
31+ const launchReplyFromPrompt =
32+ process . env . NEMOCLAW_FAKE_OPENAI_LAUNCH_REPLY_FROM_PROMPT === "1" ;
3133const requestCanaryMarker = process . env . NEMOCLAW_FAKE_OPENAI_REQUEST_CANARY_MARKER || "" ;
3234const forbiddenMarkers = ( ( ) => {
3335 try {
@@ -145,6 +147,27 @@ function requestCanaryPresent(req: IncomingMessage, raw: Buffer): boolean | unde
145147 return requestMaterial . includes ( requestCanaryMarker ) ;
146148}
147149
150+ function latestUserPrompt ( payload : JsonObject ) : string | null {
151+ const entries = Array . isArray ( payload . messages ) ? payload . messages : [ ] ;
152+ for ( let index = entries . length - 1 ; index >= 0 ; index -= 1 ) {
153+ const entry = entries [ index ] ;
154+ if ( ! entry || typeof entry !== "object" ) continue ;
155+ const message = entry as JsonObject ;
156+ if ( message . role !== "user" ) continue ;
157+ if ( typeof message . content === "string" ) return message . content ;
158+ }
159+ return null ;
160+ }
161+
162+ function requestedLaunchReply ( payload : JsonObject ) : string | null {
163+ if ( ! launchReplyFromPrompt ) return null ;
164+ const prompt = latestUserPrompt ( payload ) ;
165+ const match = prompt ?. match (
166+ / ^ J o i n t h e s e f o u r f r a g m e n t s w i t h u n d e r s c o r e s a n d p u t o n l y t h e r e s u l t o n i t s o w n l i n e : N E M O C L A W , ( [ 0 - 9 A - F ] { 12 } ) , ( F I R S T | S E C O N D ) , O K \. D o n o t u s e t o o l s \. $ / u,
167+ ) ;
168+ return match ? `NEMOCLAW_${ match [ 1 ] } _${ match [ 2 ] } _OK` : null ;
169+ }
170+
148171const server = createServer ( async ( req , res ) => {
149172 const path = requestPath ( req ) ;
150173
@@ -198,8 +221,9 @@ const server = createServer(async (req, res) => {
198221 sendJson ( res , 401 , { error : { message : "missing bearer credential" } } ) ;
199222 return ;
200223 }
224+ const content = requestedLaunchReply ( payload ) ?? chatContent ;
201225 if ( payload . stream ) {
202- sendChatSse ( res , chatContent ) ;
226+ sendChatSse ( res , content ) ;
203227 return ;
204228 }
205229 sendJson ( res , 200 , {
@@ -210,7 +234,7 @@ const server = createServer(async (req, res) => {
210234 choices : [
211235 {
212236 index : 0 ,
213- message : { role : "assistant" , content : chatContent } ,
237+ message : { role : "assistant" , content } ,
214238 finish_reason : "stop" ,
215239 } ,
216240 ] ,
0 commit comments