@quidgest/chatbot 0.3.0 → 0.4.0

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@quidgest/chatbot",
3
3
  "private": false,
4
- "version": "0.3.0",
4
+ "version": "0.4.0",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",
7
7
  "main": "dist/index.cjs",
@@ -51,7 +51,7 @@
51
51
  "vue-tsc": "^1.8.27"
52
52
  },
53
53
  "peerDependencies": {
54
- "@quidgest/ui": "^0.15.9",
54
+ "@quidgest/ui": "^0.16.0",
55
55
  "vue": "^3.5.13"
56
56
  }
57
57
  }
@@ -191,49 +191,36 @@
191
191
  }
192
192
 
193
193
  async function initChat() {
194
- const response = await axios.post(props.apiEndpoint + '/auth/login', {
195
- username: props.username,
196
- password: 'test'
197
- })
198
-
199
- if(!response.data) {
200
- addChatMessage(props.texts.loginError)
201
- setDisabledState(true)
202
- isLoading.value = false
203
- return
204
- }
194
+ try {
195
+ await axios.post(props.apiEndpoint + '/auth/login', {
196
+ username: props.username,
197
+ password: 'test'
198
+ })
205
199
 
206
- if (response.status !== 200 || !response.data.success) {
200
+ loadChatData()
201
+ } catch (error) {
207
202
  setDisabledState(true)
208
203
  addChatMessage(props.texts.loginError)
209
- console.log(`Unsuccessful login, endpoint gave status ${response.status}`)
210
- return
204
+ console.log('Error logging in: ' + error)
211
205
  }
212
-
213
- loadChatData()
214
206
  };
215
207
 
216
208
  async function loadChatData() {
217
- const response = await axios.post(props.apiEndpoint + '/prompt/load', {
218
- username: props.username,
219
- project: props.projectPath
220
- })
209
+ try {
210
+ const response = await axios.post(props.apiEndpoint + '/prompt/load', {
211
+ username: props.username,
212
+ project: props.projectPath
213
+ });
221
214
 
222
- if(!response.data) {
223
- setDisabledState(true)
224
- addChatMessage(props.texts.loginError)
225
- setDisabledState(true)
226
- isLoading.value = false
227
- return
228
- }
229
-
230
- if (response.status !== 200 || !response.data.success) {
231
- setDisabledState(true)
232
- addChatMessage(props.texts.loginError)
233
- console.log(`Unsuccessful load, endpoint gave status ${response.status}`)
234
- return
215
+ if(!response) return console.error('No response from server');
216
+
217
+ if (response.status !== 200 || !response.data.success) {
218
+ setDisabledState(true)
219
+ addChatMessage(props.texts.botIsSick)
220
+ console.log(`Unsuccessful load, endpoint gave status ${response.status}`)
221
+ return
235
222
  }
236
-
223
+
237
224
  sendInitialMessage()
238
225
  response.data.history.forEach((message: ChatBotMessageContent) => {
239
226
  const imgUrl = message.imageUrl ? props.controllerEndpoint + message.imageUrl : undefined
@@ -241,9 +228,15 @@
241
228
  message.content,
242
229
  message.type === 'ai' ? 'bot' : 'user',
243
230
  imgUrl,
244
- message.sessionID
245
- )
246
- })
231
+ message.sessionID)
232
+ })
233
+
234
+ } catch(error) {
235
+ setDisabledState(true)
236
+ addChatMessage(props.texts.botIsSick)
237
+ console.log('Error loading: ' + error)
238
+ }
239
+
247
240
  }
248
241
 
249
242
  // Modified addChatMessage to add isStreaming flag for empty bot messages
@@ -376,47 +369,50 @@
376
369
 
377
370
  isLoading.value = true
378
371
 
379
- const response = await axios.post(props.apiEndpoint + '/prompt/submit', formData, {
380
- headers: {
381
- 'Content-Type': 'text/event-stream',
382
- 'Accept': 'text/event-stream',
383
- },
384
- responseType: 'stream',
385
- adapter: 'fetch',
386
- })
372
+ try {
373
+ const response = await axios.post(props.apiEndpoint + '/prompt/submit', formData, {
374
+ headers: {
375
+ 'Content-Type': 'text/event-stream',
376
+ 'Accept': 'text/event-stream',
377
+ },
378
+ responseType: 'stream',
379
+ adapter: 'fetch',
380
+ })
387
381
 
388
- if(!response.data) {
389
- addChatMessage(props.texts.botIsSick)
390
- setDisabledState(true)
391
- isLoading.value = false
392
- return
393
- }
382
+ if(!response) return console.error('No response from server')
394
383
 
395
- const reader = response.data.getReader()
396
- const decoder = new TextDecoder("utf-8")
384
+ const reader = response.data.getReader()
385
+ const decoder = new TextDecoder("utf-8")
397
386
 
398
- while(true) {
399
- const { done, value } = await reader.read()
400
- if(done) break
401
-
402
- const chunk = decoder.decode(value, { stream: true })
403
- const eventList = chunk.match(/data:\s*({.*?})/g)
404
- if(!eventList) continue
387
+ while(true) {
388
+ const { done, value } = await reader.read()
389
+ if(done) break
390
+
391
+ const chunk = decoder.decode(value, { stream: true })
392
+ const eventList = chunk.match(/data:\s*({.*?})/g)
393
+ if(!eventList) continue
405
394
 
406
- for(const event of eventList) {
407
- try {
408
- const rawData = event.split('data:')[1].trim()
409
- const data = JSON.parse(rawData)
410
- if(msg) {
411
- msg.message += data.value
395
+ for(const event of eventList) {
396
+ try {
397
+ const rawData = event.split('data:')[1].trim()
398
+ const data = JSON.parse(rawData)
399
+ if(msg) {
400
+ msg.message += data.value
401
+ }
402
+ } catch (error) {
403
+ console.error('Error parsing match:', error)
412
404
  }
413
- } catch (error) {
414
- console.error('Error parsing match:', error)
415
405
  }
406
+ if(autoScrollEnabled.value) scrollToBottom()
416
407
  }
417
- if(autoScrollEnabled.value) scrollToBottom()
408
+
409
+ isLoading.value = false
410
+ } catch (error) {
411
+ setDisabledState(true)
412
+ addChatMessage(props.texts.botIsSick)
413
+ console.log('Error setting chat prompt: ' + error)
414
+ return
418
415
  }
419
- isLoading.value = false
420
416
  }
421
417
 
422
418
  function clearChat() {
@@ -424,21 +420,21 @@
424
420
  username: props.username,
425
421
  project: props.projectPath
426
422
  })
427
- .then((response: AxiosResponse) => {
428
- if (response.status !== 200 || !response.data.success) {
429
- setDisabledState(true)
430
- addChatMessage(props.texts.loginError)
431
- console.log(`Unsuccessful clear, endpoint gave status ${response.status}`)
432
- return
433
- }
434
- resetChat()
435
- sendInitialMessage()
436
- })
437
- .catch((error: Error) => {
423
+ .then((response: AxiosResponse) => {
424
+ if (response.status !== 200 || !response.data.success) {
438
425
  setDisabledState(true)
439
426
  addChatMessage(props.texts.loginError)
440
- console.log('Error clearing chat: ' + error)
441
- })
427
+ console.log(`Unsuccessful clear, endpoint gave status ${response.status}`)
428
+ return
429
+ }
430
+ resetChat()
431
+ sendInitialMessage()
432
+ })
433
+ .catch((error: Error) => {
434
+ setDisabledState(true)
435
+ addChatMessage(props.texts.loginError)
436
+ console.log('Error clearing chat: ' + error)
437
+ })
442
438
  }
443
439
 
444
440
  function getMessageClasses(sender: ChatBotMessageSender) {