@quidgest/chatbot 0.0.7 → 0.0.8

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 +1 @@
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}}
1
+ .q-chatbot{width:100%;padding:1rem;display:flex;flex-direction:column;height:100%}.q-chatbot input{line-height:1.5rem}.q-chatbot .q-input-group .i-text__field{border-radius:0;flex:1}.q-chatbot__content{background-color:#fff;border:1px solid #eaebec;height:100%;width:100%;display:flex;gap:.75rem;flex-direction:column;overflow:hidden}.q-chatbot__footer-container{padding:.8rem}.q-chatbot__send-container{padding-bottom:.25rem;display:flex;justify-content:flex-end}.q-chatbot__send-container .q-chatbot__send{border-radius:1rem}.q-chatbot__footer{position:sticky;padding:0 .5rem;border:1px solid #eaebec;border-radius:.25rem;bottom:0;width:100%;display:flex;flex-direction:column;gap:.25rem}.q-chatbot__footer .q-chatbot__input{min-height:50px;max-height:100px;border-bottom:1px solid #eaebec;overflow-y:auto}.q-chatbot__footer .q-text-area{max-height:100%;overflow-y:auto}.q-chatbot__footer .q-text-area .q-field__control{border:none}.q-chatbot__messages-container{display:flex;flex-direction:column;flex-grow:1;padding:0 1rem 2rem;gap:1.5rem;overflow-y: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.7",
4
+ "version": "0.0.8",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",
7
7
  "main": "dist/index.cjs",
@@ -32,8 +32,7 @@
32
32
  "lint:fix": "eslint . --fix && prettier --write --list-different src"
33
33
  },
34
34
  "dependencies": {
35
- "axios": "^1.6.7",
36
- "vue": "^3.3.11"
35
+ "axios": "^1.6.7"
37
36
  },
38
37
  "devDependencies": {
39
38
  "@types/node": "^20.11.13",
@@ -49,6 +48,7 @@
49
48
  "vue-tsc": "^1.8.25"
50
49
  },
51
50
  "peerDependencies": {
52
- "@quidgest/ui": "^0.14.1"
51
+ "@quidgest/ui": "^0.14.17",
52
+ "vue": "3.5.13"
53
53
  }
54
54
  }
@@ -2,6 +2,9 @@
2
2
  width: 100%;
3
3
  height: 100%;
4
4
  padding: 1rem;
5
+ display: flex;
6
+ flex-direction: column;
7
+ height: 100%;
5
8
 
6
9
  input {
7
10
  line-height: 1.5rem;
@@ -12,10 +15,6 @@
12
15
  flex: 1;
13
16
  }
14
17
 
15
- &__input {
16
- flex: 1;
17
- }
18
-
19
18
  &__content {
20
19
  background-color: white;
21
20
  border: 1px solid #eaebec;
@@ -24,14 +23,59 @@
24
23
  display: flex;
25
24
  flex-direction: column;
26
25
  gap: 0.75rem;
26
+ flex-direction: column;
27
+ overflow: hidden;
27
28
  }
28
29
 
30
+
31
+ &__footer-container {
32
+ padding: 0.8rem;
33
+ }
34
+
35
+ &__send-container {
36
+ padding-bottom: .25rem;
37
+ display: flex;
38
+ justify-content: flex-end;
39
+
40
+ & .q-chatbot__send {
41
+ border-radius: 1rem;
42
+ }
43
+ }
44
+
45
+ &__footer {
46
+ position: sticky;
47
+ padding: 0 .5rem;
48
+ border: 1px solid #eaebec;
49
+ border-radius: .25rem;
50
+ bottom: 0;
51
+ width: 100%;
52
+ display: flex;
53
+ flex-direction: column;
54
+ gap: .25rem;
55
+
56
+ & .q-chatbot__input {
57
+ min-height: 50px;
58
+ max-height: 100px;
59
+ border-bottom: 1px solid #eaebec;
60
+ overflow-y: auto;
61
+ }
62
+
63
+ & .q-text-area {
64
+ max-height: 100%;
65
+ overflow-y: auto;
66
+
67
+ & .q-field__control {
68
+ border: none;
69
+ }
70
+ }
71
+ }
29
72
  &__messages-container {
30
73
  display: flex;
31
74
  flex-direction: column;
75
+ flex-grow: 1;
32
76
  padding: 0 1rem 2rem 1rem;
33
77
  gap: 1.5rem;
34
- overflow: auto;
78
+ overflow-y: auto;
35
79
  }
36
80
 
37
81
  &__messages-wrapper {
@@ -1,8 +1,8 @@
1
1
  <script setup lang="ts">
2
2
  import {
3
3
  onMounted,
4
+ useTemplateRef,
4
5
  nextTick,
5
- computed,
6
6
  ref,
7
7
  watch,
8
8
  defineOptions
@@ -14,9 +14,9 @@
14
14
 
15
15
  import {
16
16
  QButton,
17
- QTextField,
18
- QInputGroup,
19
- QIcon
17
+ QTextArea,
18
+ QIcon,
19
+ QLabel
20
20
  } from '@quidgest/ui/components'
21
21
 
22
22
  import type { ResourceStrings } from '@/types/texts.type'
@@ -26,15 +26,13 @@
26
26
  } from '@/types/message.type'
27
27
 
28
28
  let messages: Ref<ChatBotMessage[]> = ref([])
29
- let msgHistoryStack: string[] = []
30
29
  let nextMessageId: number = 1
31
30
  let userPrompt: Ref<string> = ref('')
32
31
  let isLoading: Ref<boolean> = ref(false)
33
32
  let isChatDisabled: boolean = false
34
33
 
35
34
  // refs
36
- const scrollElement = ref<HTMLElement | null>(null)
37
- const promptInput = ref<HTMLInputElement | null>(null)
35
+ const scrollElement = useTemplateRef('scrollElement')
38
36
 
39
37
  export type ChatBotProps = {
40
38
  /**
@@ -68,7 +66,7 @@
68
66
  texts: () => ({
69
67
  chatbotTitle: 'ChatBot',
70
68
  qButtonTitle: 'Send message',
71
- placeholderMessage: 'Type your message here...',
69
+ inputLabel: 'What can I help with?',
72
70
  initialMessage:
73
71
  "Howdy! I am GenioBot 👋, Quidgest's personal AI assistant! How can I help you?",
74
72
  loginError:
@@ -82,10 +80,6 @@
82
80
  initChat()
83
81
  })
84
82
 
85
- const userMessages = computed(() => {
86
- return messages.value.filter((m: ChatBotMessage) => m.sender === 'user')
87
- })
88
-
89
83
  function setDisabledState(state: boolean) {
90
84
  isChatDisabled = state
91
85
  }
@@ -173,7 +167,6 @@
173
167
 
174
168
  function resetChat() {
175
169
  messages.value = []
176
- msgHistoryStack = []
177
170
  userPrompt.value = ''
178
171
  isLoading.value = false
179
172
  setDisabledState(false)
@@ -183,46 +176,6 @@
183
176
  scrollElement.value?.scrollIntoView({ behavior: 'smooth' })
184
177
  }
185
178
 
186
- function handleKey(event: KeyboardEvent) {
187
- if (promptInput.value == null) return
188
-
189
- if (event.key == 'ArrowUp') {
190
- //No user messages, no need to continue
191
- if (userMessages.value.length == 0) return
192
-
193
- //Get next message to read
194
- let lastMsgObj =
195
- userMessages.value[
196
- userMessages.value.length - 1 - msgHistoryStack.length
197
- ]
198
-
199
- //No more messages to go through
200
- if (!lastMsgObj) return
201
-
202
- //Save current prompt (even if modified) & update input
203
- msgHistoryStack.push(userPrompt.value)
204
- userPrompt.value = lastMsgObj.message
205
-
206
- //Set the cursor to the end of text
207
- nextTick(() =>
208
- setCursorPosition(
209
- promptInput.value as HTMLInputElement,
210
- lastMsgObj.message.length
211
- )
212
- )
213
- } else if (event.key == 'ArrowDown') {
214
- let previousHistoryText = msgHistoryStack.pop()
215
-
216
- if (!previousHistoryText) {
217
- //No more prompts in the stack
218
- userPrompt.value = ''
219
- return
220
- }
221
-
222
- userPrompt.value = previousHistoryText
223
- }
224
- }
225
-
226
179
  function sendMessage() {
227
180
  if (
228
181
  userPrompt.value.trim().length == 0 ||
@@ -278,11 +231,6 @@
278
231
  })
279
232
  }
280
233
 
281
- function setCursorPosition(elem: HTMLInputElement, pos: number) {
282
- elem.focus()
283
- elem.setSelectionRange(pos, pos)
284
- }
285
-
286
234
  function clearChat() {
287
235
  Axios.post(props.apiEndpoint + '/prompt/clear', {
288
236
  username: props.username,
@@ -357,31 +305,34 @@
357
305
  </div>
358
306
 
359
307
  <div ref="scrollElement"></div>
308
+
309
+ <div class="q-chatbot__footer-container">
310
+ <label> {{ props.texts.inputLabel }} </label>
311
+ <div class="q-chatbot__footer">
312
+ <div class="q-chatbot__input">
313
+ <QTextArea
314
+ v-model="userPrompt"
315
+ size="block"
316
+ autosize
317
+ resize="none"
318
+ :rows="2"
319
+ :disabled="isChatDisabled"
320
+ @keyup.enter="sendMessage" />
321
+ </div>
322
+ <div class="q-chatbot__send-container">
323
+ <QButton
324
+ :title="props.texts.qButtonTitle"
325
+ b-style="primary"
326
+ class="q-chatbot__send"
327
+ :disabled="isChatDisabled || isLoading"
328
+ :loading="isLoading"
329
+ @click="sendMessage">
330
+ <QIcon icon="send" />
331
+ </QButton>
332
+ </div>
333
+ </div>
334
+ </div>
360
335
  </div>
361
336
 
362
- <QInputGroup
363
- size="block"
364
- :disabled="isChatDisabled">
365
- <QTextField
366
- ref="promptInput"
367
- v-model="userPrompt"
368
- class="q-chatbot__input"
369
- :placeholder="props.texts.placeholderMessage"
370
- :disabled="isChatDisabled"
371
- @keyup.enter="sendMessage"
372
- @keydown="handleKey" />
373
-
374
- <template #append>
375
- <QButton
376
- :title="props.texts.qButtonTitle"
377
- b-style="primary"
378
- class="q-chatbot__send"
379
- :disabled="isChatDisabled || isLoading"
380
- :loading="isLoading"
381
- @click="sendMessage">
382
- <QIcon icon="send" />
383
- </QButton>
384
- </template>
385
- </QInputGroup>
386
337
  </div>
387
338
  </template>