@quidgest/chatbot 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/style.css CHANGED
@@ -1,93 +1 @@
1
- .q-chatbot {
2
- width: 100%;
3
- height: 100%;
4
- padding: 1rem;
5
- }
6
- .q-chatbot input {
7
- line-height: 1.5rem;
8
- }
9
- .q-chatbot .q-input-group .i-text__field {
10
- border-radius: 0;
11
- flex: 1;
12
- }
13
- .q-chatbot__input {
14
- flex: 1;
15
- }
16
- .q-chatbot__content {
17
- background-color: white;
18
- border: 1px solid #eaebec;
19
- height: 100%;
20
- width: 100%;
21
- display: flex;
22
- flex-direction: column;
23
- gap: 0.75rem;
24
- }
25
- .q-chatbot__messages-container {
26
- display: flex;
27
- flex-direction: column;
28
- padding: 0 1rem 2rem 1rem;
29
- gap: 1.5rem;
30
- overflow: auto;
31
- }
32
- .q-chatbot__messages-wrapper {
33
- display: flex;
34
- max-width: 100%;
35
- gap: 0.2rem;
36
- }
37
- .q-chatbot__messages-wrapper_right {
38
- justify-content: flex-end;
39
- }
40
- .q-chatbot__tools {
41
- display: flex;
42
- flex-direction: row;
43
- justify-content: end;
44
- max-width: 100%;
45
- }
46
- .q-chatbot__message-wrapper {
47
- display: flex;
48
- flex-direction: column;
49
- gap: 0.2rem;
50
- }
51
- .q-chatbot__message-container {
52
- display: flex;
53
- flex-direction: row;
54
- align-items: center;
55
- gap: 0.5rem;
56
- }
57
- .q-chatbot__messages-wrapper_right {
58
- justify-content: flex-end;
59
- }
60
- .q-chatbot__profile {
61
- border-radius: 50%;
62
- height: 2rem;
63
- width: 2rem;
64
- }
65
- .q-chatbot__message {
66
- min-width: 4rem;
67
- display: flex;
68
- align-items: center;
69
- padding: 0.3rem 0.5rem;
70
- background-color: #eaebec;
71
- white-space: normal;
72
- min-height: 2rem;
73
- }
74
- .q-chatbot__messages-wrapper_right .q-chatbot__message {
75
- background-color: rgba(1, 139, 210, 0.2);
76
- }
77
- .q-chatbot__sender {
78
- white-space: nowrap;
79
- color: #7c858d;
80
- font-size: 0.7rem;
81
- }
82
-
83
- @keyframes dotPulse {
84
- 0% {
85
- opacity: 0.5;
86
- }
87
- 50% {
88
- opacity: 1;
89
- }
90
- 100% {
91
- opacity: 0.5;
92
- }
93
- }
1
+ .q-chatbot{width:100%;height:100%;padding:1rem}.q-chatbot input{line-height:1.5rem}.q-chatbot .q-input-group .i-text__field{border-radius:0;flex:1}.q-chatbot__input{flex:1}.q-chatbot__content{background-color:#fff;border:1px solid #eaebec;height:100%;width:100%;display:flex;flex-direction:column;gap:.75rem}.q-chatbot__messages-container{display:flex;flex-direction:column;padding:0 1rem 2rem;gap:1.5rem;overflow:auto}.q-chatbot__messages-wrapper{display:flex;max-width:100%;gap:.2rem}.q-chatbot__tools{display:flex;flex-direction:row;justify-content:end;max-width:100%}.q-chatbot__message-wrapper{display:flex;flex-direction:column;gap:.2rem}.q-chatbot__message-container{display:flex;flex-direction:row;align-items:center;gap:.5rem}.q-chatbot__messages-wrapper_right{justify-content:flex-end}.q-chatbot__profile{border-radius:50%;height:2rem;width:2rem}.q-chatbot__message{min-width:4rem;display:flex;align-items:center;padding:.3rem .5rem;background-color:#eaebec;white-space:normal;min-height:2rem}.q-chatbot__messages-wrapper_right .q-chatbot__message{background-color:#018bd233}.q-chatbot__sender{white-space:nowrap;color:#7c858d;font-size:.7rem}@keyframes dotPulse{0%{opacity:.5}50%{opacity:1}to{opacity:.5}}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@quidgest/chatbot",
3
3
  "private": false,
4
- "version": "0.0.6",
4
+ "version": "0.0.7",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",
7
7
  "main": "dist/index.cjs",
@@ -24,10 +24,12 @@
24
24
  "src"
25
25
  ],
26
26
  "scripts": {
27
- "build": "yarn build-lib",
28
- "build-lib": "rimraf ./dist && vue-tsc --noEmit && vite build",
27
+ "build": "rimraf ./dist && vite build",
29
28
  "build-types": "vue-tsc --emitDeclarationOnly --declaration -p tsconfig.json",
30
- "lint": "eslint 'src/**/*.{ts,vue}'"
29
+ "lint": "pnpm lint:eslint && pnpm lint:prettier",
30
+ "lint:eslint": "eslint .",
31
+ "lint:prettier": "prettier src --check",
32
+ "lint:fix": "eslint . --fix && prettier --write --list-different src"
31
33
  },
32
34
  "dependencies": {
33
35
  "axios": "^1.6.7",
@@ -36,15 +38,17 @@
36
38
  "devDependencies": {
37
39
  "@types/node": "^20.11.13",
38
40
  "@vitejs/plugin-vue": "^4.5.2",
41
+ "eslint": "^9.8.0",
42
+ "eslint-plugin-prettier": "^5.2.1",
43
+ "prettier": "^3.3.3",
39
44
  "rimraf": "^5.0.5",
40
45
  "sass": "^1.70.0",
41
46
  "typescript": "^5.2.2",
42
47
  "vite": "^5.0.8",
43
48
  "vite-plugin-dts": "^3.7.3",
44
- "vue-tsc": "^1.8.25",
45
- "cross-env": "5.0.5"
49
+ "vue-tsc": "^1.8.25"
46
50
  },
47
51
  "peerDependencies": {
48
- "@quidgest/ui": "^0.13.1"
52
+ "@quidgest/ui": "^0.14.1"
49
53
  }
50
54
  }
@@ -22,7 +22,7 @@
22
22
  height: 100%;
23
23
  width: 100%;
24
24
  display: flex;
25
- flex-direction: column;
25
+ flex-direction: column;
26
26
  gap: 0.75rem;
27
27
  }
28
28
 
@@ -38,10 +38,10 @@
38
38
  display: flex;
39
39
  max-width: 100%;
40
40
  gap: 0.2rem;
41
-
42
- &_right {
43
- justify-content: flex-end;
44
- }
41
+
42
+ &_right {
43
+ justify-content: flex-end;
44
+ }
45
45
  }
46
46
 
47
47
  &__tools {
@@ -53,7 +53,7 @@
53
53
 
54
54
  &__message-wrapper {
55
55
  display: flex;
56
- flex-direction: column;
56
+ flex-direction: column;
57
57
  gap: 0.2rem;
58
58
  }
59
59
 
@@ -40,7 +40,7 @@
40
40
  })
41
41
 
42
42
  const getLocaleDate = computed(() => {
43
- if(!props.dateFormat) return props.date.toLocaleString()
43
+ if (!props.dateFormat) return props.date.toLocaleString()
44
44
 
45
45
  return formatDate(props.date, props.dateFormat)
46
46
  })
@@ -69,14 +69,13 @@
69
69
 
70
70
  <template>
71
71
  <div class="q-chatbot__message-container">
72
-
73
72
  <!-- Chatbot Image -->
74
73
  <img
75
74
  v-if="props.sender === 'bot'"
76
75
  :src="ChatBotIcon"
77
76
  alt="Chatbot"
78
77
  class="q-chatbot__profile" />
79
-
78
+
80
79
  <div class="q-chatbot__message-wrapper">
81
80
  <!-- Message header -->
82
81
  <div
@@ -87,7 +86,7 @@
87
86
 
88
87
  <!-- Message body -->
89
88
  <div class="q-chatbot__message">
90
- <QLineLoader v-if="loading" />
89
+ <QLineLoader v-if="loading" />
91
90
  <template v-else>
92
91
  <div
93
92
  class="q-chatbot__text"
@@ -102,4 +101,4 @@
102
101
  </div>
103
102
  </div>
104
103
  </div>
105
- </template>
104
+ </template>
@@ -1,5 +1,12 @@
1
1
  <script setup lang="ts">
2
- import { onMounted, nextTick, computed, ref, watch, defineOptions } from 'vue'
2
+ import {
3
+ onMounted,
4
+ nextTick,
5
+ computed,
6
+ ref,
7
+ watch,
8
+ defineOptions
9
+ } from 'vue'
3
10
  import type { Ref } from 'vue'
4
11
  import Axios from 'axios'
5
12
  import type { AxiosResponse } from 'axios'
@@ -7,14 +14,16 @@
7
14
 
8
15
  import {
9
16
  QButton,
10
- QTextField,
17
+ QTextField,
11
18
  QInputGroup,
12
19
  QIcon
13
20
  } from '@quidgest/ui/components'
14
21
 
15
22
  import type { ResourceStrings } from '@/types/texts.type'
16
- import type { ChatBotMessage, ChatBotMessageContent } from '@/types/message.type'
17
-
23
+ import type {
24
+ ChatBotMessage,
25
+ ChatBotMessageContent
26
+ } from '@/types/message.type'
18
27
 
19
28
  let messages: Ref<ChatBotMessage[]> = ref([])
20
29
  let msgHistoryStack: string[] = []
@@ -22,7 +31,7 @@
22
31
  let userPrompt: Ref<string> = ref('')
23
32
  let isLoading: Ref<boolean> = ref(false)
24
33
  let isChatDisabled: boolean = false
25
-
34
+
26
35
  // refs
27
36
  const scrollElement = ref<HTMLElement | null>(null)
28
37
  const promptInput = ref<HTMLInputElement | null>(null)
@@ -31,7 +40,7 @@
31
40
  /**
32
41
  * API Enpoint URL
33
42
  */
34
- apiEndpoint?: string,
43
+ apiEndpoint?: string
35
44
 
36
45
  /**
37
46
  * Static resource texts used by ChatBot
@@ -80,31 +89,31 @@
80
89
  function setDisabledState(state: boolean) {
81
90
  isChatDisabled = state
82
91
  }
83
-
92
+
84
93
  function initChat() {
85
94
  Axios.post(props.apiEndpoint + '/auth/login', {
86
95
  username: props.username,
87
96
  password: 'test'
88
97
  })
89
- .then((response: AxiosResponse) => {
90
- if (response.status != 200 || !response.data.success) {
98
+ .then((response: AxiosResponse) => {
99
+ if (response.status != 200 || !response.data.success) {
100
+ setDisabledState(true)
101
+ addChatMessage(props.texts.loginError)
102
+ return console.log(
103
+ `Unsuccessful login, endpoint gave status ${response.status}`
104
+ )
105
+ }
106
+
107
+ loadChatData()
108
+ })
109
+ .catch((error: Error) => {
91
110
  setDisabledState(true)
92
111
  addChatMessage(props.texts.loginError)
93
- return console.log(
94
- `Unsuccessful login, endpoint gave status ${response.status}`
112
+ console.log(
113
+ 'The following error ocurred while trying to login: \n' +
114
+ error
95
115
  )
96
- }
97
-
98
- loadChatData()
99
- })
100
- .catch((error: Error) => {
101
- setDisabledState(true)
102
- addChatMessage(props.texts.loginError)
103
- console.log(
104
- 'The following error ocurred while trying to login: \n' +
105
- error
106
- )
107
- })
116
+ })
108
117
  }
109
118
 
110
119
  function loadChatData() {
@@ -112,28 +121,33 @@
112
121
  username: props.username,
113
122
  project: props.projectPath
114
123
  })
115
- .then((response: AxiosResponse) => {
116
- if (response.status != 200 || !response.data.success) {
124
+ .then((response: AxiosResponse) => {
125
+ if (response.status != 200 || !response.data.success) {
126
+ setDisabledState(true)
127
+ addChatMessage(props.texts.loginError)
128
+ return console.log(
129
+ `Unsuccessful load, endpoint gave status ${response.status}`
130
+ )
131
+ }
132
+
133
+ sendInitialMessage()
134
+ response.data.history.forEach(
135
+ (message: ChatBotMessageContent) => {
136
+ addChatMessage(
137
+ message.content,
138
+ message.type === 'ai' ? 'bot' : 'user'
139
+ )
140
+ }
141
+ )
142
+ })
143
+ .catch((error: Error) => {
117
144
  setDisabledState(true)
118
145
  addChatMessage(props.texts.loginError)
119
- return console.log(
120
- `Unsuccessful load, endpoint gave status ${response.status}`
146
+ console.log(
147
+ 'The following error ocurred while trying to login: \n' +
148
+ error
121
149
  )
122
- }
123
-
124
- sendInitialMessage()
125
- response.data.history.forEach((message: ChatBotMessageContent) => {
126
- addChatMessage(message.content, message.type === "ai" ? "bot" : "user")
127
150
  })
128
- })
129
- .catch((error: Error) => {
130
- setDisabledState(true)
131
- addChatMessage(props.texts.loginError)
132
- console.log(
133
- 'The following error ocurred while trying to login: \n' +
134
- error
135
- )
136
- })
137
151
  }
138
152
 
139
153
  function addChatMessage(message: string, sender: 'bot' | 'user' = 'bot') {
@@ -166,11 +180,11 @@
166
180
  }
167
181
 
168
182
  function scrollToBottom() {
169
- scrollElement.value?.scrollIntoView({ behavior: 'smooth' })
183
+ scrollElement.value?.scrollIntoView({ behavior: 'smooth' })
170
184
  }
171
185
 
172
186
  function handleKey(event: KeyboardEvent) {
173
- if(promptInput.value == null) return;
187
+ if (promptInput.value == null) return
174
188
 
175
189
  if (event.key == 'ArrowUp') {
176
190
  //No user messages, no need to continue
@@ -179,9 +193,7 @@
179
193
  //Get next message to read
180
194
  let lastMsgObj =
181
195
  userMessages.value[
182
- userMessages.value.length -
183
- 1 -
184
- msgHistoryStack.length
196
+ userMessages.value.length - 1 - msgHistoryStack.length
185
197
  ]
186
198
 
187
199
  //No more messages to go through
@@ -210,7 +222,7 @@
210
222
  userPrompt.value = previousHistoryText
211
223
  }
212
224
  }
213
-
225
+
214
226
  function sendMessage() {
215
227
  if (
216
228
  userPrompt.value.trim().length == 0 ||
@@ -243,8 +255,7 @@
243
255
  method: 'POST',
244
256
  data: params,
245
257
  onDownloadProgress: (progressEvent) => {
246
- const chunk =
247
- progressEvent.event?.currentTarget.response
258
+ const chunk = progressEvent.event?.currentTarget.response
248
259
  const status = progressEvent.event?.currentTarget.status
249
260
 
250
261
  if (status != 200) return
@@ -253,18 +264,18 @@
253
264
  scrollToBottom()
254
265
  }
255
266
  })
256
- .then(({ data }) => {
257
- if (msg) msg.message = data
258
- })
259
- .catch((error) => {
260
- addChatMessage(props.texts.botIsSick)
267
+ .then(({ data }) => {
268
+ if (msg) msg.message = data
269
+ })
270
+ .catch((error) => {
271
+ addChatMessage(props.texts.botIsSick)
261
272
 
262
- setDisabledState(true)
263
- console.log(error)
264
- })
265
- .finally(() => {
266
- isLoading.value = false
267
- })
273
+ setDisabledState(true)
274
+ console.log(error)
275
+ })
276
+ .finally(() => {
277
+ isLoading.value = false
278
+ })
268
279
  }
269
280
 
270
281
  function setCursorPosition(elem: HTMLInputElement, pos: number) {
@@ -272,55 +283,55 @@
272
283
  elem.setSelectionRange(pos, pos)
273
284
  }
274
285
 
275
- function clearChat() {
286
+ function clearChat() {
276
287
  Axios.post(props.apiEndpoint + '/prompt/clear', {
277
288
  username: props.username,
278
289
  project: props.projectPath
279
290
  })
280
- .then((response: AxiosResponse) => {
281
- if (response.status != 200 || !response.data.success) {
291
+ .then((response: AxiosResponse) => {
292
+ if (response.status != 200 || !response.data.success) {
293
+ setDisabledState(true)
294
+ addChatMessage(props.texts.loginError)
295
+ return console.log(
296
+ `Unsuccessful login, endpoint gave status ${response.status}`
297
+ )
298
+ }
299
+
300
+ resetChat()
301
+ sendInitialMessage()
302
+ })
303
+ .catch((error: Error) => {
282
304
  setDisabledState(true)
283
305
  addChatMessage(props.texts.loginError)
284
- return console.log(
285
- `Unsuccessful login, endpoint gave status ${response.status}`
306
+ console.log(
307
+ 'The following error ocurred while trying to communicate with the endpoint: \n' +
308
+ error
286
309
  )
287
- }
288
-
289
- resetChat()
290
- sendInitialMessage()
291
- })
292
- .catch((error: Error) => {
293
- setDisabledState(true)
294
- addChatMessage(props.texts.loginError)
295
- console.log(
296
- 'The following error ocurred while trying to communicate with the endpoint: \n' +
297
- error
298
- )
299
- })
310
+ })
300
311
  }
301
312
 
302
313
  function getMessageClasses(sender: 'user' | 'bot') {
303
314
  const classes: string[] = ['q-chatbot__messages-wrapper']
304
315
 
305
- if(sender == 'user')
306
- classes.push('q-chatbot__messages-wrapper_right')
316
+ if (sender == 'user') classes.push('q-chatbot__messages-wrapper_right')
307
317
 
308
318
  return classes
309
319
  }
310
320
 
311
- watch(() => props.apiEndpoint, () => {
312
- resetChat()
313
- initChat()
314
- })
321
+ watch(
322
+ () => props.apiEndpoint,
323
+ () => {
324
+ resetChat()
325
+ initChat()
326
+ }
327
+ )
315
328
 
316
329
  defineOptions({ name: 'ChatBot' })
317
330
  </script>
318
331
 
319
332
  <template>
320
333
  <div class="q-chatbot">
321
- <div
322
- class="q-chatbot__content">
323
-
334
+ <div class="q-chatbot__content">
324
335
  <!-- Chat tools -->
325
336
  <div class="q-chatbot__tools">
326
337
  <QButton
@@ -338,7 +349,10 @@
338
349
  v-for="message in messages"
339
350
  :key="message.id"
340
351
  :class="getMessageClasses(message.sender)">
341
- <CBMessage v-bind="message" :date-format="props.dateFormat" :loading="isLoading && !message.message" />
352
+ <CBMessage
353
+ v-bind="message"
354
+ :date-format="props.dateFormat"
355
+ :loading="isLoading && !message.message" />
342
356
  </div>
343
357
  </div>
344
358
 
@@ -1,7 +1,4 @@
1
- import CBMessage from "./CBMessage.vue"
2
- import type { CBMessageProps } from "./CBMessage.vue"
1
+ import CBMessage from './CBMessage.vue'
2
+ import type { CBMessageProps } from './CBMessage.vue'
3
3
 
4
- export {
5
- CBMessage,
6
- CBMessageProps
7
- }
4
+ export { CBMessage, CBMessageProps }
@@ -1,11 +1,11 @@
1
1
  export type ChatBotMessage = {
2
- id: number,
3
- message: string,
4
- date: Date,
2
+ id: number
3
+ message: string
4
+ date: Date
5
5
  sender: 'bot' | 'user'
6
6
  }
7
7
 
8
8
  export type ChatBotMessageContent = {
9
- content: string,
9
+ content: string
10
10
  type: string
11
- }
11
+ }
@@ -1,3 +1,3 @@
1
1
  export type ResourceStrings = {
2
2
  [key: string]: string
3
- }
3
+ }