@@ -15,6 +15,19 @@ type SessionRecord = {
1515
1616export function createQaRunnerRuntime ( ) : PluginRuntime {
1717 const sessions = new Map < string , SessionRecord > ( ) ;
18+ const dispatchReplyWithBufferedBlockDispatcher : PluginRuntime [ "channel" ] [ "reply" ] [ "dispatchReplyWithBufferedBlockDispatcher" ] =
19+ async ( { ctx, dispatcherOptions } ) => {
20+ await dispatcherOptions . deliver (
21+ {
22+ text : `qa-echo: ${ ctx . BodyForAgent ?? ctx . Body ?? "" } ` ,
23+ } ,
24+ { kind : "final" } ,
25+ ) ;
26+ return {
27+ queuedFinal : false ,
28+ counts : { tool : 0 , block : 0 , final : 1 } ,
29+ } ;
30+ } ;
1831 return {
1932 channel : {
2033 routing : {
@@ -73,39 +86,28 @@ export function createQaRunnerRuntime(): PluginRuntime {
7386 finalizeInboundContext ( ctx : Record < string , unknown > ) {
7487 return ctx as typeof ctx & { CommandAuthorized : boolean } ;
7588 } ,
76- async dispatchReplyWithBufferedBlockDispatcher ( {
77- ctx,
78- dispatcherOptions,
79- } : {
80- ctx : { BodyForAgent ?: string ; Body ?: string } ;
81- dispatcherOptions : { deliver : ( payload : { text : string } ) => Promise < void > } ;
82- } ) {
83- await dispatcherOptions . deliver ( {
84- text : `qa-echo: ${ ctx . BodyForAgent ?? ctx . Body ?? "" } ` ,
85- } ) ;
86- } ,
89+ dispatchReplyWithBufferedBlockDispatcher,
8790 } ,
8891 inbound : {
89- async dispatchReply (
90- params : Parameters < PluginRuntime [ "channel" ] [ "inbound" ] [ "dispatchReply" ] > [ 0 ] ,
91- ) {
92+ async dispatch ( params : Parameters < PluginRuntime [ "channel" ] [ "inbound" ] [ "dispatch" ] > [ 0 ] ) {
9293 const sessionKey =
9394 typeof params . ctxPayload . SessionKey === "string"
9495 ? params . ctxPayload . SessionKey
95- : params . routeSessionKey ;
96- await params . recordInboundSession ( {
97- storePath : params . storePath ,
96+ : params . route . sessionKey ;
97+ sessions . set ( sessionKey , {
9898 sessionKey,
99- ctx : params . ctxPayload ,
100- onRecordError : params . record ?. onRecordError ?? ( ( ) => undefined ) ,
99+ body : params . ctxPayload . BodyForAgent ?? params . ctxPayload . Body ?? "" ,
101100 } ) ;
102- const dispatchResult = await params . dispatchReplyWithBufferedBlockDispatcher ( {
101+ const delivery =
102+ params . admission ?. kind === "observeOnly"
103+ ? async ( ) => ( { visibleReplySent : false } )
104+ : params . delivery . deliver ;
105+ const dispatchResult = await dispatchReplyWithBufferedBlockDispatcher ( {
103106 ctx : params . ctxPayload ,
104107 cfg : params . cfg ,
105108 dispatcherOptions : {
106- ...params . dispatcherOptions ,
107109 deliver : async ( payload , info ) => {
108- await params . delivery . deliver ( payload , info ) ;
110+ await delivery ( payload , info ) ;
109111 } ,
110112 onError : params . delivery . onError ,
111113 } ,
@@ -116,7 +118,7 @@ export function createQaRunnerRuntime(): PluginRuntime {
116118 admission : params . admission ?? { kind : "dispatch" } ,
117119 dispatched : true ,
118120 ctxPayload : params . ctxPayload ,
119- routeSessionKey : params . routeSessionKey ,
121+ routeSessionKey : params . route . sessionKey ,
120122 dispatchResult,
121123 } ;
122124 } ,
0 commit comments