Skip to content

Commit 7992321

Browse files
authored
Merge pull request #357 from iceljc/features/refine-chat-window
Features/refine chat window
2 parents f0bae75 + 78da1d5 commit 7992321

File tree

5 files changed

+29
-21
lines changed

5 files changed

+29
-21
lines changed

src/lib/helpers/conversation.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { conversationUserStateStore } from "./store";
2+
3+
/**
4+
* @param {string} conversationId
5+
*/
6+
export function buildConversationUserStates(conversationId) {
7+
const userStates = conversationUserStateStore.get(conversationId);
8+
if (!!userStates && userStates.conversationId == conversationId) {
9+
// @ts-ignore
10+
const states = userStates.states?.map(state => {
11+
return {
12+
key: state.key.data,
13+
value: state.value.data,
14+
active_rounds: state.active_rounds.data || -1
15+
};
16+
}) || [];
17+
// conversationUserStateStore.resetOne(conversationId);
18+
return states;
19+
}
20+
return [];
21+
}

src/lib/scss/custom/components/_alert.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
right: 35%;
66
z-index: 8888;
77
font-size: 0.9em;
8+
white-space: pre-line;
89

910
.alert {
1011
text-align: center;

src/lib/services/conversation-service.js

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import axios from 'axios';
22
import qs from 'qs';
33
import { replaceUrl } from '$lib/helpers/http';
44
import { conversationUserStateStore } from '$lib/helpers/store.js';
5+
import { buildConversationUserStates } from '$lib/helpers/conversation.js';
56
import { endpoints } from './api-endpoints.js';
67

78
/**
@@ -167,26 +168,6 @@ export async function sendNotification(conversationId, text, data = null) {
167168
return response.data;
168169
}
169170

170-
/**
171-
* @param {string} conversationId
172-
*/
173-
function buildConversationUserStates(conversationId) {
174-
const userStates = conversationUserStateStore.get(conversationId);
175-
if (!!userStates && userStates.conversationId == conversationId) {
176-
// @ts-ignore
177-
const states = userStates.states?.map(state => {
178-
return {
179-
key: state.key.data,
180-
value: state.value.data,
181-
active_rounds: state.active_rounds.data || -1
182-
};
183-
}) || [];
184-
// conversationUserStateStore.resetOne(conversationId);
185-
return states;
186-
}
187-
return [];
188-
}
189-
190171
/**
191172
* delete a message in conversation
192173
* @param {string} conversationId The conversation id

src/lib/services/realtime-chat-service.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { PUBLIC_SERVICE_URL } from "$env/static/public";
2+
import { buildConversationUserStates } from "$lib/helpers/conversation";
23
import { AudioRecordingWorklet } from "$lib/helpers/realtime/pcmProcessor";
34

45
// @ts-ignore
@@ -42,7 +43,10 @@ export const realtimeChat = {
4243
console.log("WebSocket connected");
4344

4445
socket?.send(JSON.stringify({
45-
event: "start"
46+
event: "start",
47+
body: {
48+
payload: JSON.stringify(buildConversationUserStates(conversationId))
49+
}
4650
}));
4751

4852
mediaStream = await navigator.mediaDevices.getUserMedia({ audio: true });

src/routes/+layout.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
errorUnsubscriber?.();
4040
});
4141
</script>
42+
4243
{#if isLoading}
4344
<Loader size={50}/>
4445
{/if}

0 commit comments

Comments
 (0)