Skip to content

Commit bed406f

Browse files
authored
Merge pull request #211 from rahulsolanki001/fix/conversation-merge-final-and-user-llm-text
fix: respect final flag in mergeMessages and handle user-llm-text event
2 parents f12166c + 6119ada commit bed406f

4 files changed

Lines changed: 16 additions & 0 deletions

File tree

client-js/client/client.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import {
3838
TranscriptData,
3939
TransportState,
4040
UICancelJobGroupData,
41+
UserLLMTextData,
4142
UICommandData,
4243
UIEventData,
4344
UIJobGroupData,
@@ -150,6 +151,7 @@ export type RTVIEventCallbacks = Partial<{
150151
onUserMuteStarted: () => void;
151152
onUserMuteStopped: () => void;
152153
onUserTranscript: (data: TranscriptData) => void;
154+
onUserLlmText: (data: UserLLMTextData) => void;
153155
onBotOutput: (data: BotOutputData) => void;
154156
/** @deprecated Use onBotOutput instead */
155157
onBotTranscript: (data: BotLLMTextData) => void;
@@ -1173,6 +1175,12 @@ export class PipecatClient extends RTVIEventEmitter {
11731175
this._options.callbacks?.onUserTranscript?.(TranscriptData);
11741176
break;
11751177
}
1178+
case RTVIMessageType.USER_LLM_TEXT: {
1179+
const llmTextData = ev.data as UserLLMTextData;
1180+
this._options.callbacks?.onUserLlmText?.(llmTextData);
1181+
this.emit(RTVIEvent.UserLlmText, llmTextData);
1182+
break;
1183+
}
11761184
case RTVIMessageType.BOT_OUTPUT: {
11771185
this._options.callbacks?.onBotOutput?.(ev.data as BotOutputData);
11781186
break;

client-js/rtvi/events.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
TranscriptData,
2222
UICommandData,
2323
UIJobGroupData,
24+
UserLLMTextData,
2425
} from "./messages";
2526

2627
export enum RTVIEvent {
@@ -65,6 +66,7 @@ export enum RTVIEvent {
6566
BotTranscript = "botTranscript",
6667

6768
// llm events
69+
UserLlmText = "userLlmText",
6870
BotLlmText = "botLlmText",
6971
BotLlmStarted = "botLlmStarted",
7072
BotLlmStopped = "botLlmStopped",
@@ -151,6 +153,7 @@ export type RTVIEvents = Partial<{
151153
botTranscript: (data: BotLLMTextData) => void;
152154

153155
// llm events
156+
userLlmText: (data: UserLLMTextData) => void;
154157
botLlmText: (data: BotLLMTextData) => void;
155158
botLlmStarted: () => void;
156159
botLlmStopped: () => void;

client-js/rtvi/messages.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ export type BotLLMTextData = {
153153
text: string;
154154
};
155155

156+
export type UserLLMTextData = {
157+
text: string;
158+
};
159+
156160
export type BotTTSTextData = {
157161
text: string;
158162
};

client-react/src/conversation/conversationActions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ export const mergeMessages = (
130130
lastMerged.role === currentMessage.role &&
131131
currentMessage.role !== "system" &&
132132
currentMessage.role !== "function_call" &&
133+
!lastMerged.final &&
133134
timeDiff < MERGE_WINDOW_MS;
134135

135136
if (shouldMerge) {

0 commit comments

Comments
 (0)