@@ -7,11 +7,13 @@ import type { EmbeddedAgentQueueMessageOutcome } from "../../agents/embedded-age
77import type { OpenClawConfig } from "../../config/types.openclaw.js" ;
88import type { TemplateContext } from "../templating.js" ;
99import type { FollowupRun , QueueSettings } from "./queue.js" ;
10+ import { createReplyOperation as createRegisteredReplyOperation } from "./reply-run-registry.js" ;
11+ import { resolveFollowupRunToolAuthorityFingerprint } from "./reply-tool-authority.js" ;
1012import {
11- createReplyOperation as createRegisteredReplyOperation ,
12- type ReplyOperation ,
13- } from "./reply-run-registry.js" ;
14- import { createMockFollowupRun , createMockTypingController } from "./test-helpers.js" ;
13+ createMockFollowupRun ,
14+ createMockReplyOperation ,
15+ createMockTypingController ,
16+ } from "./test-helpers.js" ;
1517
1618const runEmbeddedAgentMock = vi . fn ( ) ;
1719const runWithModelFallbackMock = vi . fn ( ) ;
@@ -51,12 +53,6 @@ const resolveOutboundAttachmentFromUrlMock = vi.fn();
5153const createReplyMediaContextRuntimeMock = vi . fn ( ) ;
5254const EXPECTED_STEER_QUEUE_IDENTITY =
5355 "channel-user:v1:6f3f31084a7a2a6ff17176c0c16682e64d9f21301f64ff7e5bf1173b54fadc33" ;
54- const TEST_TOOL_AUTHORITY_FINGERPRINT = "test-tool-authority" ;
55-
56- vi . mock ( "./reply-tool-authority.js" , ( ) => ( {
57- resolveFollowupRunToolAuthorityFingerprint : ( ) => "test-tool-authority" ,
58- } ) ) ;
59-
6056vi . mock ( "../../agents/model-fallback-runner.js" , ( ) => ( {
6157 runWithModelFallback : ( params : {
6258 provider : string ;
@@ -294,24 +290,6 @@ vi.mock("./reply-media-paths.runtime.js", async (importOriginal) => {
294290
295291const { runReplyAgent } = await import ( "./agent-runner.js" ) ;
296292
297- function createReplyOperation ( ) : ReplyOperation {
298- return {
299- result : undefined ,
300- toolAuthorityFingerprint : TEST_TOOL_AUTHORITY_FINGERPRINT ,
301- abortSignal : new AbortController ( ) . signal ,
302- startedAtMs : Date . now ( ) ,
303- lastActivityAtMs : Date . now ( ) ,
304- recordActivity : vi . fn ( ) ,
305- setPhase : vi . fn ( ) ,
306- bindToolAuthorityFingerprint : vi . fn ( ) ,
307- bindToolAuthorityRoute : vi . fn ( ) ,
308- freezeAbort : vi . fn ( ) ,
309- fail : vi . fn ( ) ,
310- complete : vi . fn ( ) ,
311- completeThen : vi . fn ( ) ,
312- } as unknown as ReplyOperation ;
313- }
314-
315293function makeRunReplyAgentParams (
316294 overrides : Partial < Parameters < typeof runReplyAgent > [ 0 ] > & {
317295 provider ?: string ;
@@ -322,18 +300,27 @@ function makeRunReplyAgentParams(
322300 const provider = overrides . provider ?? "whatsapp" ;
323301 const prompt = overrides . prompt ?? "generate chart" ;
324302 const workspaceDir = overrides . workspaceDir ?? "/tmp/workspace" ;
325-
326- return {
327- commandBody : prompt ,
328- followupRun : createMockFollowupRun ( {
303+ const followupRun =
304+ overrides . followupRun ??
305+ createMockFollowupRun ( {
329306 prompt,
330307 run : {
331308 agentId : "main" ,
332309 agentDir : "/tmp/agent" ,
333310 messageProvider : provider ,
334311 workspaceDir,
335312 } ,
336- } ) as unknown as FollowupRun ,
313+ } ) ;
314+ const replyOperation = overrides . replyOperation ?? createMockReplyOperation ( ) . replyOperation ;
315+ if ( overrides . isActive === true && ! replyOperation . toolAuthorityFingerprint ) {
316+ replyOperation . bindToolAuthorityFingerprint (
317+ resolveFollowupRunToolAuthorityFingerprint ( followupRun ) ,
318+ ) ;
319+ }
320+
321+ return {
322+ commandBody : prompt ,
323+ followupRun,
337324 queueKey : "main" ,
338325 resolvedQueue : { mode : "interrupt" } as QueueSettings ,
339326 shouldSteer : false ,
@@ -355,7 +342,7 @@ function makeRunReplyAgentParams(
355342 resolvedBlockStreamingBreak : "message_end" ,
356343 shouldInjectGroupIntro : false ,
357344 typingMode : "instant" ,
358- replyOperation : createReplyOperation ( ) ,
345+ replyOperation,
359346 ...overrides ,
360347 } ;
361348}
@@ -495,7 +482,7 @@ describe("runReplyAgent media path normalization", () => {
495482 queueIdentity : EXPECTED_STEER_QUEUE_IDENTITY ,
496483 onQueueAccepted : parkedSteerAcceptedMock ,
497484 taskSuggestionDeliveryMode : "gateway" ,
498- toolAuthorityFingerprint : TEST_TOOL_AUTHORITY_FINGERPRINT ,
485+ toolAuthorityFingerprint : resolveFollowupRunToolAuthorityFingerprint ( followupRun ) ,
499486 } ,
500487 ) ;
501488 expect ( enqueueFollowupRunMock ) . not . toHaveBeenCalled ( ) ;
@@ -544,7 +531,7 @@ describe("runReplyAgent media path normalization", () => {
544531 images,
545532 media : followupRun . media ,
546533 taskSuggestionDeliveryMode : undefined ,
547- toolAuthorityFingerprint : TEST_TOOL_AUTHORITY_FINGERPRINT ,
534+ toolAuthorityFingerprint : resolveFollowupRunToolAuthorityFingerprint ( followupRun ) ,
548535 } ,
549536 ) ;
550537 expect ( enqueueFollowupRunMock ) . not . toHaveBeenCalled ( ) ;
@@ -585,13 +572,17 @@ describe("runReplyAgent media path normalization", () => {
585572 } ) ;
586573
587574 it ( "latches audio only after the active reply operation accepts the steer" , async ( ) => {
575+ const followupRun = {
576+ ...createMockFollowupRun ( { prompt : "summarize the audio" } ) ,
577+ currentInboundAudio : true ,
578+ } as unknown as FollowupRun ;
588579 const operation = createRegisteredReplyOperation ( {
589580 sessionKey : "agent:main:whatsapp:direct:chat-1" ,
590581 sessionId : "session" ,
591582 resetTriggered : false ,
592583 } ) ;
593584 operation . setPhase ( "running" ) ;
594- operation . bindToolAuthorityFingerprint ( TEST_TOOL_AUTHORITY_FINGERPRINT ) ;
585+ operation . bindToolAuthorityFingerprint ( resolveFollowupRunToolAuthorityFingerprint ( followupRun ) ) ;
595586 expect ( operation . acceptedSteeredInboundAudio ) . toBe ( false ) ;
596587 queueEmbeddedAgentMessageWithOutcomeAsyncMock . mockImplementation ( async ( sessionId : string ) => ( {
597588 queued : true ,
@@ -602,16 +593,13 @@ describe("runReplyAgent media path normalization", () => {
602593
603594 await runReplyAgent (
604595 makeRunReplyAgentParams ( {
596+ followupRun,
605597 replyOperation : operation ,
606598 sessionKey : "agent:main:whatsapp:direct:chat-1" ,
607599 resolvedQueue : { mode : "steer" } as QueueSettings ,
608600 shouldSteer : true ,
609601 shouldFollowup : true ,
610602 isActive : true ,
611- followupRun : {
612- ...createMockFollowupRun ( { prompt : "summarize the audio" } ) ,
613- currentInboundAudio : true ,
614- } as unknown as FollowupRun ,
615603 } ) ,
616604 ) ;
617605
@@ -627,7 +615,7 @@ describe("runReplyAgent media path normalization", () => {
627615 queueIdentity : EXPECTED_STEER_QUEUE_IDENTITY ,
628616 onQueueAccepted : parkedSteerAcceptedMock ,
629617 taskSuggestionDeliveryMode : undefined ,
630- toolAuthorityFingerprint : TEST_TOOL_AUTHORITY_FINGERPRINT ,
618+ toolAuthorityFingerprint : operation . toolAuthorityFingerprint ,
631619 } ,
632620 ) ;
633621 expect ( enqueueFollowupRunMock ) . not . toHaveBeenCalled ( ) ;
0 commit comments