2121import java .util .concurrent .ThreadPoolExecutor ;
2222import java .util .concurrent .TimeUnit ;
2323import java .util .concurrent .atomic .AtomicInteger ;
24+ import java .util .function .Consumer ;
2425
2526/**
2627 * OpenCode 客户端门面:HTTP Server + SSE 事件流 + 本地 CLI。
@@ -226,6 +227,7 @@ public boolean isCliEnabled() {
226227 // ============================================================
227228
228229 private void copyHttpConfig (OpenCodeHttpClientConfig src ) {
230+ this .config .getHttp ().setMode (src .getMode ());
229231 this .config .getHttp ().setEnabled (src .isEnabled ());
230232 this .config .getHttp ().setStartupCheckEnabled (src .isStartupCheckEnabled ());
231233 this .config .getHttp ().setFailFastOnUnavailable (src .isFailFastOnUnavailable ());
@@ -244,7 +246,7 @@ private void copyHttpConfig(OpenCodeHttpClientConfig src) {
244246 this .config .getHttp ().setStreamMaxPoolSize (src .getStreamMaxPoolSize ());
245247 this .config .getHttp ().setStreamQueueCapacity (src .getStreamQueueCapacity ());
246248 this .config .getHttp ().setStreamKeepAliveMillis (src .getStreamKeepAliveMillis ());
247- this .config .getHttp ().setSseEventQueueCapacity (src .getSseEventQueueCapacity ());
249+ this .config .getHttp ().setStreamEventQueueCapacity (src .getStreamEventQueueCapacity ());
248250 this .config .getHttp ().setRetryOnConnectionFailure (src .isRetryOnConnectionFailure ());
249251 this .config .getHttp ().setVerifySsl (src .isVerifySsl ());
250252 this .config .getHttp ().setDefaultModel (src .getDefaultModel ());
@@ -360,10 +362,19 @@ public ChatStreamingResponse chatCompletionStream(ChatRequest request, String se
360362
361363 public ChatStreamingResponse chatCompletionStream (ChatRequest request , String sessionKey ,
362364 OpenCodeRequestContext context ) {
365+ return chatCompletionStream (request , sessionKey , context , null );
366+ }
367+
368+ /**
369+ * 流式对话,并在订阅启动前绑定增量回调,避免丢失首批分片。
370+ */
371+ public ChatStreamingResponse chatCompletionStream (ChatRequest request , String sessionKey ,
372+ OpenCodeRequestContext context ,
373+ Consumer <String > deltaConsumer ) {
363374 String sessionId = httpClient .ensureSession (sessionKey , context );
364375 PromptRequest promptRequest = ChatMessageMapper .toPromptRequest (request );
365376
366- ChatStreamingResponse stream = new ChatStreamingResponse ();
377+ ChatStreamingResponse stream = new ChatStreamingResponse (). onDelta ( deltaConsumer ) ;
367378
368379 OpenCodeSseClient .QueueSubscription subscription =
369380 sseClient .subscribeQueueSubscription (context );
0 commit comments