Skip to content

Commit 1c2c6f7

Browse files
committed
Npm lint fix
1 parent 44dcd5e commit 1c2c6f7

File tree

3 files changed

+47
-42
lines changed

3 files changed

+47
-42
lines changed

services/web/src/components/bot/ActionProvider.tsx

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import { v4 as uuidv4 } from "uuid";
1919
import superagent from "superagent";
2020
import { ChatMessage } from "./MessageParser";
2121

22-
2322
export interface ChatBotMessage {
2423
message: string;
2524
role: string;
@@ -89,11 +88,15 @@ class ActionProvider {
8988
);
9089
this.addMessageToState(message);
9190
} else {
92-
const message = this.createChatBotMessage("Bot already initialized", Math.floor(Math.random() * 65536), {
93-
loading: true,
94-
terminateLoading: true,
95-
role: "assistant",
96-
});
91+
const message = this.createChatBotMessage(
92+
"Bot already initialized",
93+
Math.floor(Math.random() * 65536),
94+
{
95+
loading: true,
96+
terminateLoading: true,
97+
role: "assistant",
98+
},
99+
);
97100
this.addMessageToState(message);
98101
}
99102
};
@@ -177,11 +180,15 @@ class ActionProvider {
177180
return;
178181
}
179182
console.log(res);
180-
const successmessage = this.createChatBotMessage(res.body.message, Math.floor(Math.random() * 65536), {
181-
loading: true,
182-
terminateLoading: true,
183-
role: "assistant",
184-
});
183+
const successmessage = this.createChatBotMessage(
184+
res.body.message,
185+
Math.floor(Math.random() * 65536),
186+
{
187+
loading: true,
188+
terminateLoading: true,
189+
role: "assistant",
190+
},
191+
);
185192
this.addMessageToState(successmessage);
186193
});
187194
};
@@ -295,7 +302,6 @@ class ActionProvider {
295302
messages: [...(state.messages || []), ...chatHistory],
296303
}));
297304
};
298-
299305
}
300306

301307
export default ActionProvider;

services/web/src/components/bot/Bot.tsx

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import React, { useState, useEffect } from "react";
1818
import config from "./config";
1919
import { APIService } from "../../constants/APIConstant";
2020
import MessageParser, { ChatMessage } from "./MessageParser";
21-
import ActionProvider from "./ActionProvider";
21+
import ActionProvider from "./ActionProvider";
2222
import Chatbot, { createChatBotMessage } from "react-chatbot-kit";
2323
import { Row, Col } from "antd";
2424
import { Space } from "antd";
@@ -77,8 +77,6 @@ const ChatBotComponent: React.FC<ChatBotComponentProps> = (props) => {
7777
messages: [],
7878
});
7979

80-
81-
8280
const headerText = (): JSX.Element => {
8381
return (
8482
<div
@@ -134,7 +132,7 @@ const ChatBotComponent: React.FC<ChatBotComponentProps> = (props) => {
134132
chatHistory = res.body?.chat_history;
135133
setChatbotState((prev) => ({
136134
...prev,
137-
messages: chatHistory.map(msg => ({
135+
messages: chatHistory.map((msg) => ({
138136
role: msg.role,
139137
content: msg.content,
140138
id: msg.id,
@@ -171,24 +169,24 @@ const ChatBotComponent: React.FC<ChatBotComponentProps> = (props) => {
171169
),
172170
customButtons: (
173171
<button
174-
className="expand-chatbot-btn"
175-
style={{ position: "absolute", top: 10, right: 10, zIndex: 1100 }}
176-
onClick={() => setExpanded((prev) => !prev)}
177-
aria-label={expanded ? "Collapse Chatbot" : "Expand Chatbot"}
178-
>
179-
180-
</button>
172+
className="expand-chatbot-btn"
173+
style={{ position: "absolute", top: 10, right: 10, zIndex: 1100 }}
174+
onClick={() => setExpanded((prev) => !prev)}
175+
aria-label={expanded ? "Collapse Chatbot" : "Expand Chatbot"}
176+
>
177+
178+
</button>
181179
),
182180
},
183181
state: chatbotState,
184182
};
185183

186184
// Convert ChatMessage[] to IMessage[] for UI
187185
const chatMessagesToIMessages = (messages: ChatMessage[]): IMessage[] =>
188-
messages.map(msg => ({
186+
messages.map((msg) => ({
189187
id: msg.id,
190188
message: msg.content,
191-
type: msg.role === "assistant" ? "bot" : "user"
189+
type: msg.role === "assistant" ? "bot" : "user",
192190
}));
193191

194192
// Dynamic initialMessages state
@@ -199,15 +197,13 @@ const ChatBotComponent: React.FC<ChatBotComponentProps> = (props) => {
199197
const history = await fetchChatHistoryFromBackend(); // returns ChatMessage[]
200198
setInitialMessages(
201199
history.length > 0
202-
? history.map(msg =>
203-
createChatBotMessage(msg.content, {})
204-
)
200+
? history.map((msg) => createChatBotMessage(msg.content, {}))
205201
: [
206202
createChatBotMessage(
207203
`Hi, Welcome to crAPI! I'm CrapBot, and I'm here to be exploited.`,
208-
{}
204+
{},
209205
),
210-
]
206+
],
211207
);
212208
}
213209
fetchHistory();
@@ -224,7 +220,7 @@ const ChatBotComponent: React.FC<ChatBotComponentProps> = (props) => {
224220
message: string;
225221
type: string; // required
226222
}
227-
223+
228224
// Remount Chatbot only on clear, reset, or init
229225
const [chatbotInstanceKey, setChatbotInstanceKey] = useState(0);
230226

@@ -263,7 +259,7 @@ const ChatBotComponent: React.FC<ChatBotComponentProps> = (props) => {
263259
// Save messages to backend and re-fetch
264260
const saveMessages = (messages: IMessage[]): void => {
265261
// Update UI state immediately (optimistic UI)
266-
setChatbotState(prev => ({
262+
setChatbotState((prev) => ({
267263
...prev,
268264
messages: iMessageToChatHistory(messages),
269265
}));
@@ -294,7 +290,7 @@ const ChatBotComponent: React.FC<ChatBotComponentProps> = (props) => {
294290

295291
// Convert IMessage[] (UI) to ChatMessage[] (backend)
296292
const iMessageToChatHistory = (messages: IMessage[]): ChatMessage[] =>
297-
messages.map(msg => ({
293+
messages.map((msg) => ({
298294
role: msg.type === "bot" ? "assistant" : "user",
299295
content: msg.message,
300296
id: msg.id,
@@ -314,11 +310,11 @@ const ChatBotComponent: React.FC<ChatBotComponentProps> = (props) => {
314310
.set("Authorization", `Bearer ${props.accessToken}`)
315311
.send({ chat_history: [] });
316312
const latestHistory = await fetchChatHistoryFromBackend();
317-
setChatbotState(prev => ({
313+
setChatbotState((prev) => ({
318314
...prev,
319315
messages: latestHistory,
320316
}));
321-
setChatbotInstanceKey(prev => prev + 1);
317+
setChatbotInstanceKey((prev) => prev + 1);
322318
} catch (err) {
323319
console.error("Failed to clear chat history on backend", err);
324320
}
@@ -333,21 +329,20 @@ const ChatBotComponent: React.FC<ChatBotComponentProps> = (props) => {
333329
.set("Authorization", `Bearer ${props.accessToken}`)
334330
.send({ chat_history: [] });
335331
const latestHistory = await fetchChatHistoryFromBackend();
336-
setChatbotState(prev => ({
332+
setChatbotState((prev) => ({
337333
...prev,
338334
messages: latestHistory,
339335
}));
340-
setChatbotInstanceKey(prev => prev + 1);
336+
setChatbotInstanceKey((prev) => prev + 1);
341337
} catch (err) {
342338
console.error("Failed to reset chat history on backend", err);
343339
}
344340
};
345341

346-
347342
return (
348343
<Row>
349344
<Col xs={10}>
350-
<div className={`app-chatbot-container${expanded ? ' expanded' : ''}`}>
345+
<div className={`app-chatbot-container${expanded ? " expanded" : ""}`}>
351346
<div style={{ maxWidth: "100%", maxHeight: "100%" }}>
352347
{/* Chatbot loads chat history from backend and renders it on UI load */}
353348
{showBot && initialMessages === null && <div>Loading chat...</div>}

services/web/src/components/bot/MessageParser.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ interface ActionProvider {
3434
handleHelp: (initRequired: boolean) => void;
3535
handleInitialize: (initRequired: boolean) => void;
3636
handleResetContext: (accessToken: string) => void;
37-
handleInitialized: (message: string, accessToken: string, chatHistory: ChatMessage[]) => void;
37+
handleInitialized: (
38+
message: string,
39+
accessToken: string,
40+
chatHistory: ChatMessage[],
41+
) => void;
3842
handleNotInitialized: () => void;
3943
handleChat: (message: string, accessToken: string) => void;
4044
}
@@ -74,7 +78,7 @@ class MessageParser {
7478
.catch((err) => {
7579
console.log("Error prefetch: ", err);
7680
});
77-
81+
7882
console.log("Initialization required:", initRequired);
7983
return [initRequired, chatHistory];
8084
}
@@ -113,7 +117,7 @@ class MessageParser {
113117
return this.actionProvider.handleInitialized(
114118
message,
115119
this.state.accessToken,
116-
this.state.chatHistory
120+
this.state.chatHistory,
117121
);
118122
} else if (this.state.initializationRequired) {
119123
return this.actionProvider.handleNotInitialized();

0 commit comments

Comments
 (0)