ai-chat-bot-interface 1.6.2 → 1.6.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/ChatUi.vue +26 -4
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ai-chat-bot-interface",
3
3
  "private": false,
4
- "version": "1.6.2",
4
+ "version": "1.6.3",
5
5
  "type": "module",
6
6
  "main": "index.js",
7
7
  "description": "A AI chat bot interface. (private)",
package/src/ChatUi.vue CHANGED
@@ -212,6 +212,7 @@ const isAnswering = ref(false);
212
212
  const isReq = ref('00');
213
213
  const historyList = ref([]);
214
214
  const isFirst = ref(false);
215
+ const turns = ref(0);
215
216
 
216
217
  const msgObj = {
217
218
  placeholder: '發消息⋯',
@@ -296,15 +297,20 @@ const props = defineProps({
296
297
  store: true,
297
298
  dishes: true,
298
299
  plan: true,
300
+ personalForm: false,
299
301
  }),
300
302
  },
301
303
  storage: {
302
304
  type: String,
303
305
  default: 'sessionStorage',
304
306
  },
307
+ needLog: {
308
+ type: Boolean,
309
+ default: false,
310
+ },
305
311
  });
306
312
 
307
- const Emits = defineEmits(['call']);
313
+ const Emits = defineEmits(['call', 'log']);
308
314
 
309
315
  const finalDefMsg = computed(() => {
310
316
  return {
@@ -349,12 +355,13 @@ onMounted(async () => {
349
355
  });
350
356
 
351
357
  const createConv = async () => {
352
- isFirst.value = true;
353
358
  const res = await post(
354
359
  'https://api.coze.cn/v1/conversation/create',
355
360
  { bot_id: props.botId, connector_id: '999' },
356
361
  { ...chatOptions.value },
357
362
  );
363
+ isFirst.value = true;
364
+ turns.value = 0;
358
365
  console.log(res);
359
366
  if (res.code === 0 && res.data) {
360
367
  conversationId.value = res.data.id || '';
@@ -459,6 +466,13 @@ const chatConv = async (data) => {
459
466
  });
460
467
  historyList.value.push(uObj);
461
468
  isReq.value = '02';
469
+ turns.value += 1;
470
+ if (props.needLog) {
471
+ Emits('log', {
472
+ turns: turns.value,
473
+ info: uObj,
474
+ });
475
+ }
462
476
  const res = await fetch(
463
477
  `https://api.coze.cn/v3/chat?conversation_id=${conversationId.value}`,
464
478
  {
@@ -511,10 +525,12 @@ const chatConv = async (data) => {
511
525
  let buffer = '';
512
526
 
513
527
  const handlePersonalForm = () => {
514
- console.log('======= End ======', historyList.value);
528
+ console.log('======= End ======', historyList.value, isFirst.value);
515
529
  if (isFirst.value) {
516
530
  historyList.value[idx].extra.push({ showType: 'personalForm' });
517
531
  isFirst.value = false;
532
+
533
+ console.log('===============', historyList.value[idx]);
518
534
  }
519
535
  };
520
536
 
@@ -527,6 +543,12 @@ const chatConv = async (data) => {
527
543
  isReq.value = '00';
528
544
  historyList.value[idx].status = 'ended';
529
545
  handlePersonalForm();
546
+ if (props.needLog) {
547
+ Emits('log', {
548
+ turns: turns.value,
549
+ info: historyList.value[idx],
550
+ });
551
+ }
530
552
  scrollToEnd();
531
553
  break;
532
554
  }
@@ -681,7 +703,7 @@ const queryHistoryList = async () => {
681
703
  });
682
704
  }
683
705
 
684
- console.log('== history ==', historyList.value);
706
+ console.log('== history ==', historyList.value, finalCardList.value);
685
707
  };
686
708
 
687
709
  const queryBotInfo = async () => {