@@ -442,7 +442,7 @@ describe("dispatchTelegramMessage draft streaming", () => {
442442 expect . objectContaining ( {
443443 chatId : 123 ,
444444 thread : { id : 777 , scope : "dm" } ,
445- minInitialChars : 30 ,
445+ minInitialChars : 0 ,
446446 } ) ,
447447 ) ;
448448 expect ( draftStream . update ) . toHaveBeenCalledWith ( "Hello" ) ;
@@ -468,6 +468,41 @@ describe("dispatchTelegramMessage draft streaming", () => {
468468 expect ( draftStream . clear ) . toHaveBeenCalledTimes ( 1 ) ;
469469 } ) ;
470470
471+ it ( "sends direct model partials through the Telegram draft transport before final delivery" , async ( ) => {
472+ const { createTelegramDraftStream : createRealTelegramDraftStream } =
473+ await vi . importActual < typeof import ( "./draft-stream.js" ) > ( "./draft-stream.js" ) ;
474+ const bot = createBot ( ) ;
475+ createTelegramDraftStream . mockImplementation ( ( params ) => createRealTelegramDraftStream ( params ) ) ;
476+ dispatchReplyWithBufferedBlockDispatcher . mockImplementation (
477+ async ( { dispatcherOptions, replyOptions } ) => {
478+ await replyOptions ?. onPartialReply ?.( { text : "Hi" } ) ;
479+ await vi . waitFor ( ( ) =>
480+ expect ( bot . api . sendMessage ) . toHaveBeenCalledWith (
481+ 123 ,
482+ "Hi" ,
483+ expect . objectContaining ( { message_thread_id : 777 } ) ,
484+ ) ,
485+ ) ;
486+ expect ( deliverReplies ) . not . toHaveBeenCalled ( ) ;
487+
488+ await dispatcherOptions . deliver ( { text : "Hi there" } , { kind : "final" } ) ;
489+ return { queuedFinal : true } ;
490+ } ,
491+ ) ;
492+
493+ await dispatchWithContext ( { context : createContext ( ) , bot } ) ;
494+
495+ await vi . waitFor ( ( ) =>
496+ expect ( bot . api . editMessageText ) . toHaveBeenCalledWith (
497+ 123 ,
498+ 777 ,
499+ "Hi there" ,
500+ expect . objectContaining ( { parse_mode : "HTML" } ) ,
501+ ) ,
502+ ) ;
503+ expect ( deliverReplies ) . not . toHaveBeenCalled ( ) ;
504+ } ) ;
505+
471506 it ( "keeps retained overflow draft previews" , async ( ) => {
472507 const draftStream = createDraftStream ( ) ;
473508 const bot = createBot ( ) ;
0 commit comments