Skip to content

Commit b354aa2

Browse files
authored
Merge pull request #1201 from buerokratt/dev
Merging dev to test
2 parents d89ad69 + 06c368f commit b354aa2

File tree

10 files changed

+151
-15
lines changed

10 files changed

+151
-15
lines changed

DSL/Resql/get-llm-chat-messages.sql

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
WITH RECURSIVE MessageChain AS (
2+
SELECT
3+
m.*
4+
FROM message m
5+
WHERE m.chat_base_id = :chatId
6+
UNION ALL
7+
SELECT
8+
m.*
9+
FROM message m
10+
INNER JOIN MessageChain mc ON m.original_base_id = mc.base_id
11+
),
12+
FilteredMessages AS (
13+
SELECT DISTINCT ON (mc.base_id) mc.*
14+
FROM MessageChain mc
15+
LEFT JOIN MessageChain mc2 ON mc.base_id = mc2.original_base_id
16+
WHERE mc2.base_id IS NULL
17+
),
18+
LatestActiveUser AS (
19+
SELECT
20+
u.id_code, u.created, u.csa_title
21+
FROM
22+
"user" u INNER JOIN (
23+
SELECT iu.id_code, max(created) AS MaxCreated
24+
FROM "user" iu
25+
WHERE iu.status = 'active'
26+
GROUP BY iu.id_code
27+
) iju ON iju.id_code = u.id_code AND iju.MaxCreated = u.created
28+
),
29+
LatestMessages AS (
30+
SELECT
31+
fm.base_id AS id,
32+
fm.chat_base_id AS chat_id,
33+
fm.content,
34+
fm.buttons,
35+
fm.options,
36+
fm.event,
37+
fm.author_id,
38+
fm.author_timestamp,
39+
fm.author_first_name,
40+
fm.author_last_name,
41+
fm.author_role,
42+
fm.forwarded_by_user,
43+
fm.forwarded_from_csa,
44+
fm.forwarded_to_csa,
45+
fm.original_base_id,
46+
fm.rating,
47+
fm.created,
48+
fm.updated,
49+
u.csa_title
50+
FROM FilteredMessages fm
51+
LEFT JOIN LatestActiveUser u ON fm.author_id = u.id_code
52+
WHERE EVENT <> 'greeting' OR EVENT IS NULL
53+
)
54+
SELECT *
55+
FROM (
56+
SELECT *
57+
FROM LatestMessages
58+
ORDER BY created DESC
59+
LIMIT 10
60+
OFFSET 1
61+
) AS LimitedMessages
62+
ORDER BY created ASC

DSL/Ruuter.private/DSL/GET/cron-tasks/delete-conversations.yml

+21-1
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,49 @@ declaration:
1111
- field: isAuth
1212
type: boolean
1313
description: "Body field 'isAuth'"
14+
headers:
15+
- field: x-ruuter-nonce
16+
type: string
17+
description: "Nonce field"
1418

1519
assignValue:
1620
assign:
1721
isAuth: ${incoming.params.isAuth}
1822

23+
getNewNonce:
24+
call: http.post
25+
args:
26+
url: "[#CHATBOT_RESQL]/get-new-nonce"
27+
result: newNonce
28+
1929
backupConversations:
2030
call: http.post
2131
args:
2232
url: "[#CHATBOT_RUUTER_PRIVATE]/chats/back-up-removable-chats"
33+
headers:
34+
x-ruuter-nonce: ${newNonce.response.body[0].nonce}
2335
body:
2436
isAuth: ${isAuth}
2537
result: chats
2638

2739
validateResponse:
2840
switch:
2941
- condition: ${chats.response.body.response.length > 0}
30-
next: emptyMessages
42+
next: getNewNonceToEmpty
3143
next: return_not_found
3244

45+
getNewNonceToEmpty:
46+
call: http.post
47+
args:
48+
url: "[#CHATBOT_RESQL]/get-new-nonce"
49+
result: newNonceToEmpty
50+
3351
emptyMessages:
3452
call: http.post
3553
args:
3654
url: "[#CHATBOT_RUUTER_PRIVATE]/chats/empty-conversations-by-chat-ids"
55+
headers:
56+
x-ruuter-nonce: ${newNonceToEmpty.response.body[0].nonce}
3757
body:
3858
chatIds: ${chats.response.body.response}
3959
result: res

DSL/Ruuter.private/DSL/POST/chats/back-up-removable-chats.yml

+12
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,23 @@ declaration:
1111
- field: isAuth
1212
type: boolean
1313
description: "Body field 'isAuth'"
14+
headers:
15+
- field: x-ruuter-nonce
16+
type: string
17+
description: "Nonce field"
18+
19+
getNewNonce:
20+
call: http.post
21+
args:
22+
url: "[#CHATBOT_RESQL]/get-new-nonce"
23+
result: newNonce
1424

1525
getRemovableConversations:
1626
call: http.post
1727
args:
1828
url: "[#CHATBOT_RUUTER_PRIVATE]/chats/chat-to-remove"
29+
headers:
30+
x-ruuter-nonce: ${newNonce.response.body[0].nonce}
1931
body:
2032
isAuth: ${incoming.body.isAuth}
2133
result: res

DSL/Ruuter.private/DSL/POST/chats/chat-to-remove.yml

+12
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,23 @@ declaration:
1111
- field: isAuth
1212
type: boolean
1313
description: "Body field 'isAuth'"
14+
headers:
15+
- field: x-ruuter-nonce
16+
type: string
17+
description: "Nonce field"
18+
19+
getNewNonce:
20+
call: http.post
21+
args:
22+
url: "[#CHATBOT_RESQL]/get-new-nonce"
23+
result: newNonce
1424

1525
getConfigurations:
1626
call: http.get
1727
args:
1828
url: "[#CHATBOT_RUUTER_PRIVATE_INTERNAL]/configs/delete-conversation-config?skipAuth=true"
29+
headers:
30+
x-ruuter-nonce: ${newNonce.response.body[0].nonce}
1931
result: configs
2032

2133
splitCall:

DSL/Ruuter.public/DSL/POST/internal/external-bot.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ logstepAZUREDS:
7575
get_chat_messages:
7676
call: http.post
7777
args:
78-
url: "[#CHATBOT_RESQL]/get-chat-messages"
78+
url: "[#CHATBOT_RESQL]/get-llm-chat-messages"
7979
body:
8080
chatId: ${sender}
8181
result: chat_messages_res
@@ -87,7 +87,7 @@ prepare_messages:
8787
headers:
8888
type: json
8989
body:
90-
prompt_message: ${skm_config.systemMessage}
90+
prompt_message: "${skm_config.systemMessage} The current date is ${currentDate}"
9191
messages: ${chat_messages_res.response.body}
9292
new_message: ${incoming.body.message ?? ''}
9393
result: prepare_messages_res
@@ -123,7 +123,7 @@ assign_value:
123123
assign:
124124
correct_value:
125125
- recipient_id: ${sender}
126-
text: ${test.response.body.choices[0].message.content.replace(/\n/g,"\\n").replace(/%/g," protsenti").replace(" \. ", ". ")}
126+
text: ${test.response.body.choices[0].message.content.replace(/\n/g,"\\n").replace(" \. ", ". ")}
127127
context: ${test.response.body.choices[0].message.context}
128128
next: check_value
129129

GUI/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
"prettier": "prettier --write \"{,!(node_modules)/**/}*.{ts,tsx,js,json,css,less,scss}\""
1212
},
1313
"dependencies": {
14-
"@buerokratt-ria/header": "^0.1.21",
14+
"@buerokratt-ria/header": "^0.1.22",
1515
"@buerokratt-ria/menu": "^0.2.6",
1616
"@buerokratt-ria/styles": "^0.0.1",
17-
"@buerokratt-ria/common-gui-components": "^0.0.4",
17+
"@buerokratt-ria/common-gui-components": "^0.0.5",
1818
"@fontsource/roboto": "^4.5.8",
1919
"@formkit/auto-animate": "^1.0.0-beta.5",
2020
"@fortaine/fetch-event-source": "^3.0.6",

GUI/src/components/Chat/Markdownify.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const Markdownify: React.FC<MarkdownifyProps> = ({ message }) => (
4141
disableParsingRawHTML: true,
4242
}}
4343
>
44-
{message ?? ''}
44+
{message?.replace(/&#x([0-9A-Fa-f]+);/g, (_, hex) => { return String.fromCharCode(parseInt(hex, 16)); }) ?? ""}
4545
</Markdown>
4646
</div>
4747
);

GUI/src/components/Chat/index.tsx

+29-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
import { ChangeEvent, FC, useEffect, useRef, useState } from 'react';
1+
import {
2+
ChangeEvent,
3+
FC,
4+
useEffect,
5+
useLayoutEffect,
6+
useRef,
7+
useState,
8+
} from 'react';
29
import { useTranslation } from 'react-i18next';
310
import { format } from 'date-fns';
411
import { et } from 'date-fns/locale';
@@ -141,6 +148,27 @@ const Chat: FC<ChatProps> = ({
141148
: null
142149
);
143150

151+
const onVisibilityChange = () => {
152+
if (document.visibilityState === 'visible') {
153+
localStorage.setItem('focused_chat', chat.id);
154+
} else if (document.visibilityState === 'hidden') {
155+
localStorage.removeItem('focused_chat');
156+
}
157+
};
158+
159+
useEffect(() => {
160+
localStorage.setItem('focused_chat', chat.id);
161+
return () => {
162+
localStorage.removeItem('focused_chat');
163+
};
164+
}, []);
165+
166+
useLayoutEffect(() => {
167+
document.addEventListener('visibilitychange', onVisibilityChange);
168+
return () =>
169+
document.removeEventListener('visibilitychange', onVisibilityChange);
170+
}, []);
171+
144172
useEffect(() => {
145173
getMessages();
146174
}, []);

docker-compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ services:
4848
- application.logging.printStackTrace=true
4949
- application.internalRequests.disabled=true
5050
- server.port=8088
51-
- application.externalAuthAllowed=/cron-tasks/delete-conversations
51+
- application.externalAuthAllowed=/cron-tasks/delete-conversations,chats/back-up-removable-chats,chats/chat-to-remove,chats/empty-conversations-by-chat-ids
5252
volumes:
5353
- ./DSL/Ruuter.private/DSL:/DSL
5454
- ./constants.ini:/app/constants.ini

notification-server/src/server.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,21 @@ app.post("/dequeue", async (req, res) => {
6565
}
6666
});
6767

68-
app.post("/add-chat-to-termination-queue", (req, res) => {
69-
try{
68+
app.post("/add-chat-to-termination-queue", express.json(), express.text(), (req, res) => {
69+
try {
70+
const body = typeof req.body === "string" ? JSON.parse(req.body) : req.body;
71+
7072
addToTerminationQueue(
71-
req.body.chatId,
73+
body.chatId,
7274
() => fetch(`${process.env.RUUTER_URL}/chats/end`, {
7375
method: 'POST',
7476
headers: {
7577
'content-type': 'application/json',
76-
'cookie': req.body.cookie || req.headers.cookie,
78+
'cookie': body.cookie || req.headers.cookie,
7779
},
7880
body: JSON.stringify({
7981
message: {
80-
chatId: req.body.chatId,
82+
chatId: body.chatId,
8183
authorRole: 'end-user',
8284
event: 'CLIENT_LEFT_FOR_UNKNOWN_REASONS',
8385
authorTimestamp: new Date().toISOString(),
@@ -87,7 +89,7 @@ app.post("/add-chat-to-termination-queue", (req, res) => {
8789
);
8890

8991
res.status(200).json({ response: 'Chat will be terminated soon' });
90-
} catch {
92+
} catch (error) {
9193
res.status(500).json({ response: 'error' });
9294
}
9395
});

0 commit comments

Comments
 (0)