@@ -38,7 +38,12 @@ type AgentRunParams = {
3838 onPartialReply ?: ( payload : { text ?: string } ) => Promise < void > | void ;
3939 onAssistantMessageStart ?: ( ) => Promise < void > | void ;
4040 onReasoningStream ?: ( payload : { text ?: string } ) => Promise < void > | void ;
41- onBlockReply ?: ( payload : { text ?: string ; mediaUrls ?: string [ ] } ) => Promise < void > | void ;
41+ onBlockReply ?: ( payload : {
42+ text ?: string ;
43+ mediaUrls ?: string [ ] ;
44+ isReasoning ?: boolean ;
45+ isCommentary ?: boolean ;
46+ } ) => Promise < void > | void ;
4247 onToolResult ?: ( payload : ReplyPayload ) => Promise < void > | void ;
4348 shouldEmitToolResult ?: ( ) => boolean ;
4449 shouldEmitToolOutput ?: ( ) => boolean ;
@@ -183,6 +188,7 @@ function createMinimalRun(params?: {
183188 shouldSteer ?: boolean ;
184189 shouldFollowup ?: boolean ;
185190 resolvedQueueMode ?: string ;
191+ currentInboundEventKind ?: FollowupRun [ "currentInboundEventKind" ] ;
186192 sessionCtx ?: Partial < TemplateContext > ;
187193 runOverrides ?: Partial < FollowupRun [ "run" ] > ;
188194} ) {
@@ -201,6 +207,7 @@ function createMinimalRun(params?: {
201207 prompt : "hello" ,
202208 summaryLine : "hello" ,
203209 enqueuedAt : Date . now ( ) ,
210+ currentInboundEventKind : params ?. currentInboundEventKind ,
204211 run : {
205212 sessionId : "session" ,
206213 sessionKey,
@@ -1409,6 +1416,108 @@ describe("runReplyAgent typing (heartbeat)", () => {
14091416 } ) ;
14101417 } ) ;
14111418
1419+ it . each ( [
1420+ { label : "empty output" , payloads : [ ] } ,
1421+ { label : "reasoning-only output" , payloads : [ { text : "internal" , isReasoning : true } ] } ,
1422+ { label : "commentary-only output" , payloads : [ { text : "internal" , isCommentary : true } ] } ,
1423+ { label : "directive-only output" , payloads : [ { text : "[[reply_to_current]]" } ] } ,
1424+ ] ) ( "surfaces successful $label through normal reply delivery" , async ( { payloads } ) => {
1425+ state . runEmbeddedAgentMock . mockResolvedValueOnce ( { payloads, meta : { } } ) ;
1426+ const { run } = createMinimalRun ( {
1427+ runOverrides : { config : { channels : { whatsapp : { replyToMode : "first" } } } } ,
1428+ } ) ;
1429+
1430+ const result = await run ( ) ;
1431+ const payloadsResult = Array . isArray ( result ) ? result : [ result ] ;
1432+
1433+ expect ( payloadsResult ) . toContainEqual (
1434+ expect . objectContaining ( {
1435+ text : expect . stringContaining ( "did not produce a visible reply" ) ,
1436+ isError : true ,
1437+ replyToId : "msg" ,
1438+ } ) ,
1439+ ) ;
1440+ } ) ;
1441+
1442+ it . each ( [
1443+ { lane : "reasoning" , payload : { text : "internal" , isReasoning : true } } ,
1444+ { lane : "commentary" , payload : { text : "internal" , isCommentary : true } } ,
1445+ ] ) ( "does not let streamed $lane suppress the empty-reply fallback" , async ( { payload } ) => {
1446+ const onBlockReply = vi . fn ( ) ;
1447+ state . runEmbeddedAgentMock . mockImplementationOnce ( async ( params : AgentRunParams ) => {
1448+ await params . onBlockReply ?.( payload ) ;
1449+ return { payloads : [ ] , meta : { } } ;
1450+ } ) ;
1451+ const { run } = createMinimalRun ( {
1452+ blockStreamingEnabled : true ,
1453+ opts : {
1454+ onBlockReply,
1455+ reasoningPayloadsEnabled : true ,
1456+ commentaryPayloadsEnabled : true ,
1457+ } ,
1458+ } ) ;
1459+
1460+ const result = await run ( ) ;
1461+ const payloads = Array . isArray ( result ) ? result : [ result ] ;
1462+
1463+ expect ( onBlockReply ) . toHaveBeenCalled ( ) ;
1464+ expect ( onBlockReply . mock . calls [ 0 ] ?. [ 0 ] ) . toEqual ( expect . objectContaining ( payload ) ) ;
1465+ expect ( payloads ) . toContainEqual (
1466+ expect . objectContaining ( {
1467+ text : expect . stringContaining ( "did not produce a visible reply" ) ,
1468+ isError : true ,
1469+ } ) ,
1470+ ) ;
1471+ } ) ;
1472+
1473+ it . each ( [
1474+ {
1475+ label : "NO_REPLY" ,
1476+ result : {
1477+ payloads : [ { text : "NO_REPLY" } ] ,
1478+ meta : { finalAssistantVisibleText : "NO_REPLY" } ,
1479+ } ,
1480+ } ,
1481+ {
1482+ label : "accepted child spawn" ,
1483+ result : {
1484+ payloads : [ ] ,
1485+ meta : { } ,
1486+ acceptedSessionSpawns : [ { runId : "child" , childSessionKey : "agent:main:child" } ] ,
1487+ } ,
1488+ } ,
1489+ { label : "yielded continuation" , result : { payloads : [ ] , meta : { yielded : true } } } ,
1490+ {
1491+ label : "pending tool continuation" ,
1492+ result : { payloads : [ ] , meta : { pendingToolCalls : [ { name : "hosted_tool" } ] } } ,
1493+ } ,
1494+ ] ) ( "keeps successful $label completions silent" , async ( { result } ) => {
1495+ state . runEmbeddedAgentMock . mockResolvedValueOnce ( result ) ;
1496+ const { run } = createMinimalRun ( ) ;
1497+
1498+ await expect ( run ( ) ) . resolves . toBeUndefined ( ) ;
1499+ } ) ;
1500+
1501+ it . each ( [
1502+ {
1503+ label : "room event" ,
1504+ params : { currentInboundEventKind : "room_event" as const } ,
1505+ } ,
1506+ {
1507+ label : "internal handoff" ,
1508+ params : {
1509+ runOverrides : {
1510+ inputProvenance : { kind : "internal_system" as const , sourceTool : "restart-sentinel" } ,
1511+ } ,
1512+ } ,
1513+ } ,
1514+ ] ) ( "keeps successful empty $label completions silent" , async ( { params } ) => {
1515+ state . runEmbeddedAgentMock . mockResolvedValueOnce ( { payloads : [ ] , meta : { } } ) ;
1516+ const { run } = createMinimalRun ( params ) ;
1517+
1518+ await expect ( run ( ) ) . resolves . toBeUndefined ( ) ;
1519+ } ) ;
1520+
14121521 it . each ( [
14131522 {
14141523 label : "silent token" ,
@@ -1750,10 +1859,40 @@ describe("runReplyAgent typing (heartbeat)", () => {
17501859 }
17511860 } ) ;
17521861
1753- it ( "surfaces a configured backend failure when fallback produces no visible reply" , async ( ) => {
1754- state . runEmbeddedAgentMock . mockResolvedValueOnce ( {
1755- payloads : [ { text : "NO_REPLY" } ] ,
1756- meta : { } ,
1862+ it . each ( [
1863+ {
1864+ label : "NO_REPLY" ,
1865+ payload : { text : "NO_REPLY" } ,
1866+ opts : undefined ,
1867+ streamed : false ,
1868+ } ,
1869+ {
1870+ label : "reasoning-only output with reasoning enabled" ,
1871+ payload : { text : "internal reasoning" , isReasoning : true } ,
1872+ opts : { reasoningPayloadsEnabled : true } ,
1873+ streamed : false ,
1874+ } ,
1875+ {
1876+ label : "streamed reasoning-only output with reasoning enabled" ,
1877+ payload : { text : "internal reasoning" , isReasoning : true } ,
1878+ opts : { reasoningPayloadsEnabled : true , onBlockReply : vi . fn ( ) } ,
1879+ streamed : true ,
1880+ } ,
1881+ {
1882+ label : "commentary-only output with commentary enabled" ,
1883+ payload : { text : "internal commentary" , isCommentary : true } ,
1884+ opts : { commentaryPayloadsEnabled : true } ,
1885+ streamed : false ,
1886+ } ,
1887+ ] ) ( "surfaces a configured backend failure when fallback produces $label" , async ( testCase ) => {
1888+ state . runEmbeddedAgentMock . mockImplementationOnce ( async ( params : AgentRunParams ) => {
1889+ if ( testCase . streamed ) {
1890+ await params . onBlockReply ?.( testCase . payload ) ;
1891+ }
1892+ return {
1893+ payloads : [ testCase . payload ] ,
1894+ meta : { } ,
1895+ } ;
17571896 } ) ;
17581897 const fallbackSpy = vi
17591898 . spyOn ( modelFallbackModule , "runWithModelFallback" )
@@ -1776,6 +1915,8 @@ describe("runReplyAgent typing (heartbeat)", () => {
17761915
17771916 try {
17781917 const { run } = createMinimalRun ( {
1918+ opts : testCase . opts ,
1919+ blockStreamingEnabled : testCase . streamed ,
17791920 runOverrides : {
17801921 provider : "lmstudio" ,
17811922 model : "gemma-4-e4b-it" ,
0 commit comments