@quidgest/chatbot 0.0.4 → 0.0.6

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
@@ -13,9 +13,6 @@
13
13
  .q-chatbot__input {
14
14
  flex: 1;
15
15
  }
16
- .q-chatbot .clear-btn {
17
- color: red;
18
- }
19
16
  .q-chatbot__content {
20
17
  background-color: white;
21
18
  border: 1px solid #eaebec;
@@ -23,14 +20,14 @@
23
20
  width: 100%;
24
21
  display: flex;
25
22
  flex-direction: column;
26
- overflow: auto;
27
- gap: 1.5rem;
23
+ gap: 0.75rem;
28
24
  }
29
25
  .q-chatbot__messages-container {
30
26
  display: flex;
31
27
  flex-direction: column;
32
28
  padding: 0 1rem 2rem 1rem;
33
29
  gap: 1.5rem;
30
+ overflow: auto;
34
31
  }
35
32
  .q-chatbot__messages-wrapper {
36
33
  display: flex;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@quidgest/chatbot",
3
3
  "private": false,
4
- "version": "0.0.4",
4
+ "version": "0.0.6",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",
7
7
  "main": "dist/index.cjs",
@@ -31,8 +31,7 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "axios": "^1.6.7",
34
- "vue": "^3.3.11",
35
- "cross-env": "5.0.5"
34
+ "vue": "^3.3.11"
36
35
  },
37
36
  "devDependencies": {
38
37
  "@types/node": "^20.11.13",
@@ -42,9 +41,10 @@
42
41
  "typescript": "^5.2.2",
43
42
  "vite": "^5.0.8",
44
43
  "vite-plugin-dts": "^3.7.3",
45
- "vue-tsc": "^1.8.25"
44
+ "vue-tsc": "^1.8.25",
45
+ "cross-env": "5.0.5"
46
46
  },
47
47
  "peerDependencies": {
48
- "@quidgest/ui": "0.9.7"
48
+ "@quidgest/ui": "^0.13.1"
49
49
  }
50
50
  }
@@ -16,19 +16,14 @@
16
16
  flex: 1;
17
17
  }
18
18
 
19
- .clear-btn {
20
- color: red;
21
- }
22
-
23
19
  &__content {
24
20
  background-color: white;
25
21
  border: 1px solid #eaebec;
26
22
  height: 100%;
27
23
  width: 100%;
28
24
  display: flex;
29
- flex-direction: column;
30
- overflow: auto;
31
- gap: 1.5rem;
25
+ flex-direction: column;
26
+ gap: 0.75rem;
32
27
  }
33
28
 
34
29
  &__messages-container {
@@ -36,6 +31,7 @@
36
31
  flex-direction: column;
37
32
  padding: 0 1rem 2rem 1rem;
38
33
  gap: 1.5rem;
34
+ overflow: auto;
39
35
  }
40
36
 
41
37
  &__messages-wrapper {
@@ -1,7 +1,7 @@
1
1
  <script setup lang="ts">
2
2
  import { computed } from 'vue'
3
3
  import ChatBotIcon from '@/assets/chatbot.png'
4
- import { QLineLoader } from '@quidgest/ui'
4
+ import { QLineLoader } from '@quidgest/ui/components'
5
5
 
6
6
  export interface CBMessageProps {
7
7
  /*
@@ -23,6 +23,11 @@
23
23
  * If the message is loading
24
24
  */
25
25
  loading?: boolean
26
+
27
+ /**
28
+ * Project locale
29
+ */
30
+ dateFormat?: string
26
31
  }
27
32
 
28
33
  const props = withDefaults(defineProps<CBMessageProps>(), {
@@ -35,12 +40,31 @@
35
40
  })
36
41
 
37
42
  const getLocaleDate = computed(() => {
38
- return props.date.toLocaleString()
43
+ if(!props.dateFormat) return props.date.toLocaleString()
44
+
45
+ return formatDate(props.date, props.dateFormat)
39
46
  })
40
47
 
41
48
  const messageHeader = computed(() => {
42
49
  return `${senderName.value} ${getLocaleDate.value}`
43
50
  })
51
+
52
+ function formatDate(date: Date, format: string) {
53
+ const day = date.getDate().toString().padStart(2, '0')
54
+ const month = (date.getMonth() + 1).toString().padStart(2, '0')
55
+ const year = date.getFullYear().toString().padStart(2, '0')
56
+ const hours = date.getHours().toString().padStart(2, '0')
57
+ const minutes = date.getMinutes().toString().padStart(2, '0')
58
+ const seconds = date.getSeconds().toString().padStart(2, '0')
59
+
60
+ return format
61
+ .replace('dd', day)
62
+ .replace('MM', month)
63
+ .replace('yyyy', year)
64
+ .replace('HH', hours)
65
+ .replace('mm', minutes)
66
+ .replace('ss', seconds)
67
+ }
44
68
  </script>
45
69
 
46
70
  <template>
@@ -10,21 +10,21 @@
10
10
  QTextField,
11
11
  QInputGroup,
12
12
  QIcon
13
- } from '@quidgest/ui'
13
+ } from '@quidgest/ui/components'
14
14
 
15
15
  import type { ResourceStrings } from '@/types/texts.type'
16
- import type { ChatBotMessage, ChatBotMessageContent } from '@/types/message.type'
16
+ import type { ChatBotMessage, ChatBotMessageContent } from '@/types/message.type'
17
17
 
18
18
 
19
19
  let messages: Ref<ChatBotMessage[]> = ref([])
20
20
  let msgHistoryStack: string[] = []
21
21
  let nextMessageId: number = 1
22
22
  let userPrompt: Ref<string> = ref('')
23
+ let isLoading: Ref<boolean> = ref(false)
23
24
  let isChatDisabled: boolean = false
24
- let isLoading: boolean = false
25
25
 
26
26
  // refs
27
- const messagesContainer = ref<HTMLElement | null>(null)
27
+ const scrollElement = ref<HTMLElement | null>(null)
28
28
  const promptInput = ref<HTMLInputElement | null>(null)
29
29
 
30
30
  export type ChatBotProps = {
@@ -47,6 +47,11 @@
47
47
  * Project aplication path
48
48
  */
49
49
  projectPath: string
50
+
51
+ /**
52
+ * Project locale
53
+ */
54
+ dateFormat?: string
50
55
  }
51
56
 
52
57
  const props = withDefaults(defineProps<ChatBotProps>(), {
@@ -66,7 +71,6 @@
66
71
 
67
72
  onMounted(() => {
68
73
  initChat()
69
- nextTick(scrollChatToBottom)
70
74
  })
71
75
 
72
76
  const userMessages = computed(() => {
@@ -139,6 +143,8 @@
139
143
  date: new Date(),
140
144
  sender: sender
141
145
  })
146
+
147
+ nextTick(scrollToBottom)
142
148
  }
143
149
 
144
150
  function getLastMessage() {
@@ -155,19 +161,12 @@
155
161
  messages.value = []
156
162
  msgHistoryStack = []
157
163
  userPrompt.value = ''
158
- isLoading = false
164
+ isLoading.value = false
159
165
  setDisabledState(false)
160
166
  }
161
167
 
162
- function scrollChatToBottom() {
163
- if(messagesContainer.value == null) return;
164
-
165
- const element = messagesContainer.value
166
- setTimeout(
167
- () =>
168
- (element.scrollIntoView(false)),
169
- 100
170
- )
168
+ function scrollToBottom() {
169
+ scrollElement.value?.scrollIntoView({ behavior: 'smooth' })
171
170
  }
172
171
 
173
172
  function handleKey(event: KeyboardEvent) {
@@ -215,14 +214,13 @@
215
214
  function sendMessage() {
216
215
  if (
217
216
  userPrompt.value.trim().length == 0 ||
218
- isLoading ||
217
+ isLoading.value ||
219
218
  isChatDisabled
220
219
  )
221
220
  return
222
221
 
223
222
  addChatMessage(userPrompt.value, 'user')
224
223
 
225
- scrollChatToBottom()
226
224
  setChatPrompt(userPrompt.value)
227
225
 
228
226
  userPrompt.value = '' //Clear user input
@@ -239,7 +237,7 @@
239
237
  user: props.username
240
238
  }
241
239
 
242
- isLoading = true
240
+ isLoading.value = true
243
241
  Axios({
244
242
  url: props.apiEndpoint + '/prompt/message',
245
243
  method: 'POST',
@@ -252,6 +250,7 @@
252
250
  if (status != 200) return
253
251
 
254
252
  if (msg) msg.message = chunk
253
+ scrollToBottom()
255
254
  }
256
255
  })
257
256
  .then(({ data }) => {
@@ -264,7 +263,7 @@
264
263
  console.log(error)
265
264
  })
266
265
  .finally(() => {
267
- isLoading = false
266
+ isLoading.value = false
268
267
  })
269
268
  }
270
269
 
@@ -320,36 +319,36 @@
320
319
  <template>
321
320
  <div class="q-chatbot">
322
321
  <div
323
- ref="messagesContainer"
324
322
  class="q-chatbot__content">
325
323
 
326
324
  <!-- Chat tools -->
327
325
  <div class="q-chatbot__tools">
328
- <q-button
326
+ <QButton
329
327
  :title="props.texts.qButtonTitle"
330
- b-style="plain"
331
- class="clear-btn"
328
+ b-style="secondary"
332
329
  :disabled="isChatDisabled"
333
330
  borderless
334
331
  @click="clearChat">
335
- <q-icon icon="bin" />
336
- </q-button>
332
+ <QIcon icon="bin" />
333
+ </QButton>
337
334
  </div>
338
335
 
339
336
  <div class="q-chatbot__messages-container">
340
337
  <div
341
338
  v-for="message in messages"
342
339
  :key="message.id"
343
- :class="getMessageClasses">
344
- <CBMessage v-bind="message" :loading="isLoading && !message.message" />
340
+ :class="getMessageClasses(message.sender)">
341
+ <CBMessage v-bind="message" :date-format="props.dateFormat" :loading="isLoading && !message.message" />
345
342
  </div>
346
343
  </div>
344
+
345
+ <div ref="scrollElement"></div>
347
346
  </div>
348
347
 
349
- <q-input-group
348
+ <QInputGroup
350
349
  size="block"
351
350
  :disabled="isChatDisabled">
352
- <q-text-field
351
+ <QTextField
353
352
  ref="promptInput"
354
353
  v-model="userPrompt"
355
354
  class="q-chatbot__input"
@@ -359,15 +358,16 @@
359
358
  @keydown="handleKey" />
360
359
 
361
360
  <template #append>
362
- <q-button
361
+ <QButton
363
362
  :title="props.texts.qButtonTitle"
364
363
  b-style="primary"
365
364
  class="q-chatbot__send"
366
- :disabled="isChatDisabled"
365
+ :disabled="isChatDisabled || isLoading"
366
+ :loading="isLoading"
367
367
  @click="sendMessage">
368
- <q-icon icon="send" />
369
- </q-button>
368
+ <QIcon icon="send" />
369
+ </QButton>
370
370
  </template>
371
- </q-input-group>
371
+ </QInputGroup>
372
372
  </div>
373
373
  </template>