Skip to content

Commit 5f3d56a

Browse files
authored
fix(gateway): preserve chat media dispatch state (#106702)
1 parent 9166b23 commit 5f3d56a

3 files changed

Lines changed: 17 additions & 10 deletions

File tree

‎src/gateway/server-methods/chat-send-reply-dispatch.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ describe("createChatSendReplyDispatch", () => {
5353
},
5454
userTurnRecorder: { markBlocked },
5555
});
56+
expect(dispatch.hasAppendedWebchatAgentMedia()).toBe(false);
5657
const blockedPayload = setReplyPayloadMetadata(
5758
{ text: "blocked" },
5859
{ beforeAgentRunBlocked: true },

‎src/gateway/server-methods/chat-send-reply-dispatch.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,5 +224,10 @@ export function createChatSendReplyDispatch(params: {
224224
}
225225
},
226226
});
227-
return { deliveredReplies, dispatcher, onModelSelected };
227+
return {
228+
deliveredReplies,
229+
dispatcher,
230+
hasAppendedWebchatAgentMedia: () => appendedWebchatAgentMedia,
231+
onModelSelected,
232+
};
228233
}

‎src/gateway/server-methods/chat.ts‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ import {
6363
stripInlineDirectiveTagsForDisplay,
6464
sanitizeReplyDirectiveId,
6565
} from "../../utils/directive-tags.js";
66-
import { INTERNAL_MESSAGE_CHANNEL, isOperatorUiClient } from "../../utils/message-channel.js";
66+
import { isOperatorUiClient } from "../../utils/message-channel.js";
6767
import { listGatewayAgentsBasic } from "../agent-list.js";
6868
import {
6969
boundInFlightRunSnapshotForChatHistory,
@@ -1246,13 +1246,14 @@ export const chatHandlers: GatewayRequestHandlers = {
12461246
});
12471247

12481248
let agentRunStarted = false;
1249-
const { deliveredReplies, dispatcher, onModelSelected } = createChatSendReplyDispatch({
1250-
accountId,
1251-
isAgentRunStarted: () => agentRunStarted,
1252-
logGateway: context.logGateway,
1253-
session: preparedSession.value,
1254-
userTurnRecorder,
1255-
});
1249+
const { deliveredReplies, dispatcher, hasAppendedWebchatAgentMedia, onModelSelected } =
1250+
createChatSendReplyDispatch({
1251+
accountId,
1252+
isAgentRunStarted: () => agentRunStarted,
1253+
logGateway: context.logGateway,
1254+
session: preparedSession.value,
1255+
userTurnRecorder,
1256+
});
12561257
let queuedFollowupEnqueued = false;
12571258
let pendingDispatchLifecycleError:
12581259
| {
@@ -1789,7 +1790,7 @@ export const chatHandlers: GatewayRequestHandlers = {
17891790
: finalPayloadEntries;
17901791
// Non-agent command paths can enqueue only block replies. If no visible final
17911792
// supersedes them, fold those blocks into the final WebChat message.
1792-
const rawFinalPayloads = appendedWebchatAgentMedia
1793+
const rawFinalPayloads = hasAppendedWebchatAgentMedia()
17931794
? []
17941795
: [
17951796
...commandBlockPayloadEntriesForDelivery,

0 commit comments

Comments
 (0)