Skip to content

Commit 00cade8

Browse files
author
Bogdan Tsechoev
committed
Merge branch 'master' into select_ai_model
2 parents 0812a79 + da38a60 commit 00cade8

File tree

4 files changed

+42
-12
lines changed

4 files changed

+42
-12
lines changed

ui/packages/platform/src/pages/Bot/Command/Command.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ export const Command = React.memo((props: Props) => {
168168
useEffect(() => {
169169
if (!inputRef.current) return
170170
if (window.innerWidth > theme.breakpoints.values.md) inputRef.current.focus()
171+
setValue('')
171172
}, [threadId]);
172173

173174

ui/packages/platform/src/pages/Bot/Messages/Message/CodeBlock.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import languages from 'react-syntax-highlighter/dist/esm/languages/prism/support
66
import ExpandMoreIcon from "@material-ui/icons/ExpandMore";
77
import FileCopyOutlinedIcon from '@material-ui/icons/FileCopyOutlined';
88
import CheckCircleOutlineIcon from '@material-ui/icons/CheckCircleOutline';
9+
import CodeIcon from '@material-ui/icons/Code';
910

1011
const useStyles = makeStyles((theme) => ({
1112
container: {
@@ -38,18 +39,27 @@ const useStyles = makeStyles((theme) => ({
3839
width: '0.813rem',
3940
},
4041
summary: {
42+
color: 'rgb(166, 38, 164)',
4143
textDecoration: 'underline',
4244
textDecorationStyle: 'dotted',
4345
cursor: 'pointer',
4446
backgroundColor: 'transparent',
4547
boxShadow: 'none',
4648
display: 'inline-flex',
47-
minHeight: '32px!important',
49+
minHeight: '2rem!important',
4850
padding: 0,
4951
'&:hover': {
5052
textDecoration: 'none'
5153
}
5254
},
55+
summaryText: {
56+
display: 'inline-flex',
57+
alignItems: 'center'
58+
},
59+
summaryTextIcon: {
60+
marginRight: 8,
61+
fontSize: '1rem'
62+
},
5363
details: {
5464
padding: 0,
5565
backgroundColor: 'transparent'
@@ -117,7 +127,12 @@ export const CodeBlock = memo(({ value, language }: CodeBlockProps) => {
117127
return (
118128
<Accordion expanded={expanded} onChange={handleToggle} className={classes.accordion}>
119129
<AccordionSummary expandIcon={<ExpandMoreIcon />} className={classes.summary}>
120-
<Typography>{expanded ? 'Hide' : 'Show'} code block ({codeLines.length} LOC)</Typography>
130+
<Typography
131+
className={classes.summaryText}
132+
>
133+
<CodeIcon className={classes.summaryTextIcon} />
134+
{expanded ? 'Hide' : 'Show'} code block ({codeLines.length} LOC)
135+
</Typography>
121136
</AccordionSummary>
122137
<AccordionDetails className={classes.details}>
123138
<div className={classes.container}>

ui/packages/platform/src/pages/Bot/hooks.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,30 +50,37 @@ type UseAiBotReturnType = {
5050
changeChatVisibility: (threadId: string, isPublic: boolean) => void;
5151
isChangeVisibilityLoading: boolean;
5252
unsubscribe: (threadId: string) => void;
53+
chatsList: UseBotChatsListHook['chatsList'];
54+
chatsListLoading: UseBotChatsListHook['loading'];
55+
getChatsList: UseBotChatsListHook['getChatsList']
5356
model: UseLLMModelsList['model'],
5457
setModel: UseLLMModelsList['setModel']
5558
llmModels: UseLLMModelsList['llmModels']
5659
}
5760

5861
type UseAiBotArgs = {
5962
threadId?: string;
60-
prevThreadId?: string;
61-
onChatLoadingError?: () => void;
63+
orgId?: number
6264
}
6365

6466
export const useAiBot = (args: UseAiBotArgs): UseAiBotReturnType => {
65-
const { threadId, onChatLoadingError } = args;
67+
const { threadId, orgId } = args;
6668
const { showMessage, closeSnackbar } = useAlertSnackbar();
6769
const { llmModels, model, setModel } = useLLMModelsList();
6870
let location = useLocation<{skipReloading?: boolean}>();
6971

72+
const {
73+
chatsList,
74+
loading: chatsListLoading,
75+
getChatsList,
76+
} = useBotChatsList(orgId);
77+
7078
const [messages, setMessages] = useState<BotMessage[] | null>(null);
7179
const [isLoading, setLoading] = useState<boolean>(false);
7280
const [error, setError] = useState<ErrorType | null>(null);
7381
const [wsLoading, setWsLoading] = useState<boolean>(false);
74-
const [isChangeVisibilityLoading, setIsChangeVisibilityLoading] = useState<boolean>(false);
82+
const [isChangeVisibilityLoading, setIsChangeVisibilityLoading] = useState<boolean>(false)
7583

76-
7784
const token = localStorage.getAuthToken()
7885

7986
const onWebSocketError = (error: WebSocketEventMap['error']) => {
@@ -105,6 +112,9 @@ export const useAiBot = (args: UseAiBotArgs): UseAiBotReturnType => {
105112
});
106113
}
107114
}
115+
} else if (threadId !== messageData.thread_id) {
116+
const threadInList = chatsList?.find((item) => item.thread_id === messageData.thread_id)
117+
if (!threadInList) getChatsList()
108118
}
109119
} else {
110120
showMessage('An error occurred. Please try again')
@@ -150,7 +160,6 @@ export const useAiBot = (args: UseAiBotArgs): UseAiBotReturnType => {
150160
if (response && response.length > 0) {
151161
setMessages(response);
152162
} else {
153-
if (onChatLoadingError) onChatLoadingError();
154163
setError({
155164
code: 404,
156165
message: 'Specified chat not found or you have no access.',
@@ -181,7 +190,6 @@ export const useAiBot = (args: UseAiBotArgs): UseAiBotReturnType => {
181190
} else if (threadId) {
182191
subscribe(threadId)
183192
}
184-
185193
return () => {
186194
isCancelled = true;
187195
};
@@ -309,6 +317,9 @@ export const useAiBot = (args: UseAiBotArgs): UseAiBotReturnType => {
309317
clearChat,
310318
messages,
311319
unsubscribe,
320+
chatsList,
321+
chatsListLoading,
322+
getChatsList,
312323
model,
313324
setModel,
314325
llmModels
@@ -319,7 +330,7 @@ type UseBotChatsListHook = {
319330
chatsList: BotMessage[] | null;
320331
error: Response | null;
321332
loading: boolean;
322-
getChatsList: () => void
333+
getChatsList: () => void;
323334
};
324335

325336
export const useBotChatsList = (orgId?: number): UseBotChatsListHook => {

ui/packages/platform/src/pages/Bot/index.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,14 @@ export const BotPage = (props: BotPageProps) => {
106106
unsubscribe,
107107
model,
108108
setModel,
109-
llmModels
109+
llmModels,
110+
chatsListLoading,
111+
getChatsList,
112+
chatsList
110113
} = useAiBot({
111114
threadId: match.params.threadId,
115+
orgId: orgData.id
112116
});
113-
const {chatsList, loading: chatsListLoading, getChatsList} = useBotChatsList(orgData.id);
114117

115118
const matches = useMediaQuery(theme.breakpoints.down('sm'));
116119

0 commit comments

Comments
 (0)