Skip to content

Commit b62c32a

Browse files
author
Jicheng Lu
committed
receive json
1 parent e75b2c6 commit b62c32a

File tree

2 files changed

+51
-35
lines changed

2 files changed

+51
-35
lines changed

src/lib/services/signalr-service.js

Lines changed: 49 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -74,100 +74,115 @@ export const signalr = {
7474
// register handlers for the hub methods
7575
connection.on('OnConversationInitFromClient', (conversation) => {
7676
// do something when receiving a message, such as updating the UI or showing a notification
77-
if (conversationId === conversation.id) {
78-
console.log(`[OnConversationInitFromClient] ${conversation.id}: ${conversation.title}`);
79-
this.onConversationInitFromClient(conversation);
77+
const obj = JSON.parse(conversation);
78+
if (conversationId === obj?.id) {
79+
console.log(`[OnConversationInitFromClient] ${obj.id}: ${obj.title}`);
80+
this.onConversationInitFromClient(obj);
8081
}
8182
});
8283

8384
// register handlers for the hub methods
8485
connection.on('OnMessageReceivedFromClient', (message) => {
8586
// do something when receiving a message, such as updating the UI or showing a notification
86-
if (conversationId === message.conversation_id) {
87-
console.log(`[OnMessageReceivedFromClient] ${message.sender.role}: ${message.text}`);
88-
this.onMessageReceivedFromClient(message);
87+
const obj = JSON.parse(message);
88+
if (conversationId === obj?.conversation_id) {
89+
console.log(`[OnMessageReceivedFromClient] ${obj.sender.role}: ${obj.text}`);
90+
this.onMessageReceivedFromClient(obj);
8991
}
9092
});
9193

9294
connection.on('OnMessageReceivedFromCsr', (message) => {
9395
// do something when receiving a message, such as updating the UI or showing a notification
94-
if (conversationId === message.conversation_id) {
95-
console.log(`[OnMessageReceivedFromCsr] ${message.role}: ${message.content}`);
96-
this.onMessageReceivedFromCsr(message);
96+
const obj = JSON.parse(message);
97+
if (conversationId === obj?.conversation_id) {
98+
console.log(`[OnMessageReceivedFromCsr] ${obj.role}: ${obj.content}`);
99+
this.onMessageReceivedFromCsr(obj);
97100
}
98101
});
99102

100103
connection.on('OnMessageReceivedFromAssistant', (message) => {
101104
// do something when receiving a message, such as updating the UI or showing a notification
102-
if (conversationId === message?.conversation_id) {
103-
console.log(`[OnMessageReceivedFromAssistant] ${message.sender.role}: ${message.text}`);
104-
this.onMessageReceivedFromAssistant(message);
105+
const obj = JSON.parse(message);
106+
if (conversationId === obj?.conversation_id) {
107+
console.log(`[OnMessageReceivedFromAssistant] ${obj.sender.role}: ${obj.text}`);
108+
this.onMessageReceivedFromAssistant(obj);
105109
}
106110
});
107111

108112
connection.on('OnNotificationGenerated', (message) => {
109-
if (conversationId === message?.conversation_id) {
110-
this.onNotificationGenerated(message);
113+
const obj = JSON.parse(message);
114+
if (conversationId === obj?.conversation_id) {
115+
this.onNotificationGenerated(obj);
111116
}
112117
});
113118

114119
connection.on('OnConversationContentLogGenerated', (log) => {
115-
if (conversationId === log?.conversation_id) {
116-
this.onConversationContentLogGenerated(log);
120+
const obj = JSON.parse(log);
121+
if (conversationId === obj?.conversation_id) {
122+
this.onConversationContentLogGenerated(obj);
117123
}
118124
});
119125

120126
connection.on('OnConversateStateLogGenerated', (log) => {
121-
if (conversationId === log?.conversation_id) {
122-
this.onConversationStateLogGenerated(log);
127+
const obj = JSON.parse(log);
128+
if (conversationId === obj?.conversation_id) {
129+
this.onConversationStateLogGenerated(obj);
123130
}
124131
});
125132

126133
connection.on('OnStateChangeGenerated', (log) => {
127-
if (conversationId === log?.conversation_id) {
128-
this.onStateChangeGenerated(log);
134+
const obj = JSON.parse(log);
135+
if (conversationId === obj?.conversation_id) {
136+
this.onStateChangeGenerated(obj);
129137
}
130138
});
131139

132140
connection.on('OnAgentQueueChanged', (log) => {
133-
if (conversationId === log?.conversation_id) {
134-
this.onAgentQueueChanged(log);
141+
const obj = JSON.parse(log);
142+
if (conversationId === obj?.conversation_id) {
143+
this.onAgentQueueChanged(obj);
135144
}
136145
});
137146

138147
connection.on('OnSenderActionGenerated', (data) => {
139-
if (conversationId === data?.conversation_id) {
140-
this.onSenderActionGenerated(data);
148+
const obj = JSON.parse(data);
149+
if (conversationId === obj?.conversation_id) {
150+
this.onSenderActionGenerated(obj);
141151
}
142152
});
143153

144154
connection.on('OnMessageDeleted', (data) => {
145-
if (conversationId === data?.conversation_id) {
146-
this.onConversationMessageDeleted(data);
155+
const obj = JSON.parse(data);
156+
if (conversationId === obj?.conversation_id) {
157+
this.onConversationMessageDeleted(obj);
147158
}
148159
});
149160

150161
connection.on('BeforeReceiveLlmStreamMessage', data => {
151-
if (conversationId === data?.conversation_id) {
152-
this.beforeReceiveLlmStreamMessage(data);
162+
const obj = JSON.parse(data);
163+
if (conversationId === obj?.conversation_id) {
164+
this.beforeReceiveLlmStreamMessage(obj);
153165
}
154166
});
155167

156168
connection.on('OnReceiveLlmStreamMessage', data => {
157-
if (conversationId === data?.conversation_id) {
158-
this.onReceiveLlmStreamMessage(data);
169+
const obj = JSON.parse(data);
170+
if (conversationId === obj?.conversation_id) {
171+
this.onReceiveLlmStreamMessage(obj);
159172
}
160173
});
161174

162175
connection.on('AfterReceiveLlmStreamMessage', data => {
163-
if (conversationId === data?.conversation_id) {
164-
this.afterReceiveLlmStreamMessage(data);
176+
const obj = JSON.parse(data);
177+
if (conversationId === obj?.conversation_id) {
178+
this.afterReceiveLlmStreamMessage(obj);
165179
}
166180
});
167181

168182
connection.on('OnIndicationReceived', data => {
169-
if (conversationId === data?.conversation_id) {
170-
this.onIndicationReceived(data);
183+
const obj = JSON.parse(data);
184+
if (conversationId === obj?.conversation_id) {
185+
this.onIndicationReceived(obj);
171186
}
172187
});
173188
},

src/routes/chat/[agentId]/[conversationId]/chat-box.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,8 @@
430430
await tick();
431431
lastBotMsg = findLastBotMessage(dialogs);
432432
lastMsg = dialogs.slice(-1)[0];
433-
assignMessageDisclaimer(dialogs)
433+
assignMessageDisclaimer(dialogs);
434+
groupedDialogs = groupDialogs(dialogs);
434435
await tick();
435436
436437
autoScrollToBottom();

0 commit comments

Comments
 (0)