@quidgest/chatbot 0.5.1 → 0.5.3
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/README.md +1 -2
- package/dist/components/ChatBot/types.d.ts +3 -1
- package/dist/components/ChatBotInput/ChatBotInput.vue.d.ts +3 -3
- package/dist/components/ChatBotInput/__tests__/ChatBotInput.spec.d.ts +1 -0
- package/dist/components/ChatBotInput/index.d.ts +2 -2
- package/dist/components/ChatBotInput/types.d.ts +4 -4
- package/dist/components/ChatBotMessage/__tests__/ChatBotMessage.spec.d.ts +1 -0
- package/dist/components/ChatBotMessage/__tests__/ChatBotMessageButtons.spec.d.ts +1 -0
- package/dist/components/ChatBotMessage/types.d.ts +3 -2
- package/dist/components/ChatToolBar/__tests__/ChatToolBar.spec.d.ts +1 -0
- package/dist/components/FieldPreview/__tests__/FieldPreview.spec.d.ts +1 -0
- package/dist/components/MarkdownRender/__tests__/MarkdownRender.spec.d.ts +1 -0
- package/dist/components/PulseDots/__tests__/PulseDots.spec.d.ts +1 -0
- package/dist/composables/__tests__/useChatMessages.spec.d.ts +1 -0
- package/dist/composables/__tests__/useSSE.spec.d.ts +1 -0
- package/dist/composables/useChatMessages.d.ts +2 -1
- package/dist/composables/useSSE.d.ts +1 -2
- package/dist/composables/useTexts.d.ts +2 -0
- package/dist/index.js +16 -16
- package/dist/index.mjs +2924 -1770
- package/dist/style.css +1 -1
- package/dist/test/setup.d.ts +1 -0
- package/dist/utils/__tests__/parseFieldValue.spec.d.ts +1 -0
- package/package.json +27 -5
- package/src/assets/styles/preview-file.scss +70 -0
- package/src/assets/styles/styles.scss +190 -222
- package/src/components/ChatBot/ChatBot.vue +345 -368
- package/src/components/ChatBot/types.ts +35 -33
- package/src/components/ChatBotInput/ChatBotInput.vue +188 -190
- package/src/components/ChatBotInput/__tests__/ChatBotInput.spec.ts +279 -0
- package/src/components/ChatBotInput/__tests__/__snapshots__/ChatBotInput.spec.ts.snap +25 -0
- package/src/components/ChatBotInput/index.ts +2 -2
- package/src/components/ChatBotInput/types.ts +25 -25
- package/src/components/ChatBotMessage/ChatBotMessage.vue +159 -134
- package/src/components/ChatBotMessage/ChatBotMessageButtons.vue +179 -164
- package/src/components/ChatBotMessage/__tests__/ChatBotMessage.spec.ts +256 -0
- package/src/components/ChatBotMessage/__tests__/ChatBotMessageButtons.spec.ts +199 -0
- package/src/components/ChatBotMessage/__tests__/__snapshots__/ChatBotMessage.spec.ts.snap +35 -0
- package/src/components/ChatBotMessage/__tests__/__snapshots__/ChatBotMessageButtons.spec.ts.snap +25 -0
- package/src/components/ChatBotMessage/types.ts +54 -53
- package/src/components/ChatToolBar/ChatToolBar.vue +68 -64
- package/src/components/ChatToolBar/__tests__/ChatToolBar.spec.ts +118 -0
- package/src/components/ChatToolBar/__tests__/__snapshots__/ChatToolBar.spec.ts.snap +11 -0
- package/src/components/ChatToolBar/types.ts +12 -12
- package/src/components/FieldPreview/FieldPreview.vue +56 -58
- package/src/components/FieldPreview/__tests__/FieldPreview.spec.ts +72 -0
- package/src/components/FieldPreview/__tests__/__snapshots__/FieldPreview.spec.ts.snap +25 -0
- package/src/components/FieldPreview/field-preview.scss +26 -26
- package/src/components/FieldPreview/types.ts +5 -5
- package/src/components/MarkdownRender/MarkdownRender.vue +15 -15
- package/src/components/MarkdownRender/__tests__/MarkdownRender.spec.ts +68 -0
- package/src/components/MarkdownRender/__tests__/__snapshots__/MarkdownRender.spec.ts.snap +8 -0
- package/src/components/MarkdownRender/markdown-render.scss +19 -20
- package/src/components/MarkdownRender/types.ts +3 -3
- package/src/components/PulseDots/PulseDots.vue +17 -17
- package/src/components/PulseDots/__tests__/PulseDots.spec.ts +35 -0
- package/src/components/PulseDots/__tests__/__snapshots__/PulseDots.spec.ts.snap +7 -0
- package/src/components/PulseDots/__tests__/__snapshots__/pulse-dots.spec.ts.snap +7 -0
- package/src/components/PulseDots/pulse-dots.scss +24 -23
- package/src/composables/__tests__/useChatMessages.spec.ts +51 -0
- package/src/composables/__tests__/useSSE.spec.ts +132 -0
- package/src/composables/useChatApi.ts +128 -134
- package/src/composables/useChatMessages.ts +46 -48
- package/src/composables/useSSE.ts +75 -76
- package/src/composables/useTexts.ts +30 -30
- package/src/test/setup.ts +36 -0
- package/src/utils/__tests__/parseFieldValue.spec.ts +27 -0
- package/src/utils/parseFieldValue.ts +12 -0
- package/src/utils/helper.ts +0 -12
- /package/dist/utils/{helper.d.ts → parseFieldValue.d.ts} +0 -0
|
@@ -1,55 +1,57 @@
|
|
|
1
|
+
import { ChatBotFile } from '../ChatBotInput'
|
|
2
|
+
|
|
1
3
|
export type ChatBotProps = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
apiEndpoint?: string
|
|
5
|
+
controllerEndpoint?: string
|
|
6
|
+
username: string
|
|
7
|
+
projectPath: string
|
|
8
|
+
userImage?: string
|
|
9
|
+
chatbotImage?: string
|
|
10
|
+
dateFormat: string
|
|
11
|
+
agentData?: AgentData
|
|
12
|
+
availableAgents?: AvailableAgents[]
|
|
11
13
|
}
|
|
12
14
|
|
|
13
15
|
export type AvailableAgents = {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
key: string
|
|
17
|
+
value: string
|
|
18
|
+
formId: string
|
|
17
19
|
}
|
|
18
20
|
|
|
19
21
|
export type AgentData = {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
id: string
|
|
23
|
+
jobId: string
|
|
24
|
+
formId: string
|
|
23
25
|
}
|
|
24
26
|
|
|
25
27
|
export type FieldData = {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
name: string
|
|
29
|
+
type: string
|
|
30
|
+
text: string
|
|
31
|
+
applied?: boolean
|
|
30
32
|
}
|
|
31
33
|
|
|
32
34
|
export type AppliedFieldData = {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
+
name: string
|
|
36
|
+
text: unknown
|
|
35
37
|
}
|
|
36
38
|
|
|
37
39
|
export type ChatMessage = {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
40
|
+
id: number
|
|
41
|
+
message: string
|
|
42
|
+
date: Date
|
|
43
|
+
sender: ChatBotMessageSender
|
|
44
|
+
sessionID: string
|
|
45
|
+
file?: ChatBotFile
|
|
46
|
+
isWelcomeMessage?: boolean
|
|
47
|
+
fields?: FieldData[]
|
|
46
48
|
}
|
|
47
49
|
|
|
48
50
|
export type ChatBotMessageContent = {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
content: string
|
|
52
|
+
type: string
|
|
53
|
+
sessionID: string
|
|
54
|
+
imageUrl?: string
|
|
53
55
|
}
|
|
54
56
|
|
|
55
57
|
export type ChatBotMessageSender = 'bot' | 'user'
|
|
@@ -1,195 +1,193 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
2
|
+
<q-label :label="texts.inputLabel" />
|
|
3
|
+
<div
|
|
4
|
+
class="q-chatbot__footer"
|
|
5
|
+
:class="chatBotFooterClasses"
|
|
6
|
+
@dragover.prevent="onDragOver"
|
|
7
|
+
@dragleave.prevent="onDragLeave"
|
|
8
|
+
@drop.prevent="onDrop">
|
|
9
|
+
<div class="q-chatbot__input-wrapper">
|
|
10
|
+
<div
|
|
11
|
+
v-if="selectedFile"
|
|
12
|
+
class="q-chatbot__file-preview">
|
|
13
|
+
<img
|
|
14
|
+
v-if="isImageFile"
|
|
15
|
+
class="q-chatbot__image-preview"
|
|
16
|
+
:src="filePreviewUrl"
|
|
17
|
+
tabindex="0"
|
|
18
|
+
:alt="texts.imagePreview" />
|
|
19
|
+
<div
|
|
20
|
+
v-else
|
|
21
|
+
class="q-chatbot__file-preview"
|
|
22
|
+
tabindex="0">
|
|
23
|
+
<q-icon
|
|
24
|
+
icon="file"
|
|
25
|
+
class="q-chatbot__file-icon" />
|
|
26
|
+
<span class="q-chatbot__file-name">{{ selectedFile.name }}</span>
|
|
27
|
+
</div>
|
|
28
|
+
<q-button
|
|
29
|
+
class="q-chatbot__remove-file"
|
|
30
|
+
tabindex="0"
|
|
31
|
+
flat
|
|
32
|
+
round
|
|
33
|
+
@click="removeFile">
|
|
34
|
+
<q-icon icon="remove" />
|
|
35
|
+
</q-button>
|
|
36
|
+
</div>
|
|
37
|
+
<div class="q-chatbot__input">
|
|
38
|
+
<q-text-area
|
|
39
|
+
v-model="userPrompt"
|
|
40
|
+
size="block"
|
|
41
|
+
autosize
|
|
42
|
+
resize="none"
|
|
43
|
+
:rows="2"
|
|
44
|
+
:disabled="props.disabled"
|
|
45
|
+
@keyup.enter="sendMessage" />
|
|
46
|
+
</div>
|
|
47
|
+
<div class="q-chatbot__send-container">
|
|
48
|
+
<q-button
|
|
49
|
+
:title="texts.imageUpload"
|
|
50
|
+
class="q-chatbot__upload"
|
|
51
|
+
:disabled="props.disabled || props.loading || !!selectedFile"
|
|
52
|
+
@click="triggerImageUpload">
|
|
53
|
+
<q-icon icon="upload" />
|
|
54
|
+
</q-button>
|
|
55
|
+
|
|
56
|
+
<!-- Hidden file input -->
|
|
57
|
+
<input
|
|
58
|
+
id="file-upload"
|
|
59
|
+
ref="fileInput"
|
|
60
|
+
type="file"
|
|
61
|
+
:accept="acceptedFileTypes"
|
|
62
|
+
class="hidden-input"
|
|
63
|
+
@change="handleFileUpload" />
|
|
64
|
+
|
|
65
|
+
<q-button
|
|
66
|
+
:title="texts.sendMessage"
|
|
67
|
+
variant="bold"
|
|
68
|
+
class="q-chatbot__send"
|
|
69
|
+
:disabled="isSendButtonDisabled"
|
|
70
|
+
:readonly="isSendButtonDisabled"
|
|
71
|
+
@click="sendMessage">
|
|
72
|
+
<q-icon icon="send" />
|
|
73
|
+
</q-button>
|
|
74
|
+
</div>
|
|
75
|
+
</div>
|
|
76
|
+
</div>
|
|
66
77
|
</template>
|
|
67
78
|
|
|
68
79
|
<script setup lang="ts">
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
imageInput.value?.click()
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
function handleImageUpload(event: Event) {
|
|
186
|
-
// Store the selected image in imageInput
|
|
187
|
-
const target = event.target as HTMLInputElement
|
|
188
|
-
imageInput.value = target
|
|
189
|
-
|
|
190
|
-
if (target.files && target.files[0]) {
|
|
191
|
-
imagePreviewUrl.value = URL.createObjectURL(target.files[0])
|
|
192
|
-
hasSelectedImage.value = true
|
|
193
|
-
}
|
|
194
|
-
}
|
|
80
|
+
// Components
|
|
81
|
+
import { QLabel, QButton, QTextArea, QIcon } from '@quidgest/ui/components'
|
|
82
|
+
|
|
83
|
+
// Composables
|
|
84
|
+
import { useTexts } from '@/composables/useTexts'
|
|
85
|
+
|
|
86
|
+
// Utils
|
|
87
|
+
import { ref, computed } from 'vue'
|
|
88
|
+
|
|
89
|
+
// Types
|
|
90
|
+
import type { ChatBotInputProps, ChatBotFile } from './'
|
|
91
|
+
|
|
92
|
+
const props = defineProps<ChatBotInputProps>()
|
|
93
|
+
|
|
94
|
+
const emit = defineEmits<{
|
|
95
|
+
'send-message': [prompt: string, file?: ChatBotFile]
|
|
96
|
+
}>()
|
|
97
|
+
|
|
98
|
+
const texts = useTexts()
|
|
99
|
+
|
|
100
|
+
const fileInput = ref<HTMLInputElement | null>(null)
|
|
101
|
+
const selectedFile = ref<File | null>(null)
|
|
102
|
+
const filePreviewUrl = ref<string>('')
|
|
103
|
+
const isDragging = ref(false)
|
|
104
|
+
|
|
105
|
+
const acceptedFileTypes = computed(() => '.png,.jpeg,.jpg,.svg,.webp,.pdf,.doc,.docx')
|
|
106
|
+
const isImageFile = computed(() => {
|
|
107
|
+
if (!selectedFile.value) return false
|
|
108
|
+
|
|
109
|
+
return selectedFile.value.type.startsWith('image/') ?? false
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
const userPrompt = ref(props.userPrompt ?? '')
|
|
113
|
+
|
|
114
|
+
const isSendButtonDisabled = computed(() => {
|
|
115
|
+
return props.disabled || props.loading || userPrompt.value.trim().length === 0
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
function onDragOver(event: DragEvent) {
|
|
119
|
+
event.preventDefault()
|
|
120
|
+
if (!props.disabled) {
|
|
121
|
+
isDragging.value = true
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const chatBotFooterClasses = computed(() => {
|
|
126
|
+
return {
|
|
127
|
+
'q-chatbot__footer-disabled': props.disabled,
|
|
128
|
+
'drag-over': isDragging.value && !selectedFile.value
|
|
129
|
+
}
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
function onDragLeave(event: DragEvent) {
|
|
133
|
+
event.preventDefault()
|
|
134
|
+
isDragging.value = false
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function onDrop(event: DragEvent) {
|
|
138
|
+
event.preventDefault()
|
|
139
|
+
isDragging.value = false
|
|
140
|
+
|
|
141
|
+
if (props.disabled || selectedFile.value) return
|
|
142
|
+
|
|
143
|
+
const files = event.dataTransfer?.files
|
|
144
|
+
if (!files) return
|
|
145
|
+
handleFileSelection(files[0])
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function handleFileSelection(file: File) {
|
|
149
|
+
selectedFile.value = file
|
|
150
|
+
if (file.type.startsWith('image/')) {
|
|
151
|
+
filePreviewUrl.value = URL.createObjectURL(file)
|
|
152
|
+
} else {
|
|
153
|
+
filePreviewUrl.value = ''
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function sendMessage() {
|
|
158
|
+
if (userPrompt.value.trim() === '' || props.loading || props.disabled) return
|
|
159
|
+
|
|
160
|
+
// Check if an image is selected
|
|
161
|
+
if (selectedFile.value) {
|
|
162
|
+
const fileData: ChatBotFile = {
|
|
163
|
+
fileData: selectedFile.value,
|
|
164
|
+
previewUrl: filePreviewUrl.value ?? ''
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
emit('send-message', userPrompt.value, fileData)
|
|
168
|
+
removeFile()
|
|
169
|
+
} else emit('send-message', userPrompt.value)
|
|
170
|
+
|
|
171
|
+
userPrompt.value = ''
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function removeFile() {
|
|
175
|
+
selectedFile.value = null
|
|
176
|
+
filePreviewUrl.value = ''
|
|
177
|
+
|
|
178
|
+
if (fileInput.value) {
|
|
179
|
+
fileInput.value.value = ''
|
|
180
|
+
fileInput.value.files = null
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function triggerImageUpload() {
|
|
185
|
+
fileInput.value?.click()
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function handleFileUpload(event: Event) {
|
|
189
|
+
const target = event.target as HTMLInputElement
|
|
190
|
+
|
|
191
|
+
if (target.files?.[0]) handleFileSelection(target.files[0])
|
|
192
|
+
}
|
|
195
193
|
</script>
|