ai-chat-bot-interface 1.6.2 → 1.6.4

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": "ai-chat-bot-interface",
3
3
  "private": false,
4
- "version": "1.6.2",
4
+ "version": "1.6.4",
5
5
  "type": "module",
6
6
  "main": "index.js",
7
7
  "description": "A AI chat bot interface. (private)",
package/src/App.vue CHANGED
@@ -1,17 +1,31 @@
1
1
  <script setup>
2
2
  import ChatUi from './ChatUi.vue';
3
+ const handleLog = (log) => {
4
+ console.log('== message log ==', log);
5
+ };
3
6
  </script>
4
7
 
5
8
  <template>
6
9
  <div style="width: 100vw; height: 100vh">
7
10
  <chat-ui
8
- bot-id="7572460298389962778"
11
+ bot-id="7574379096097439754"
9
12
  token="sat_cSmj7ZyuePbkEpOKR7F259YuIfp2fjX9rJ3Om2O0gB9JzrGjAk8pSL269rbu8kzr"
10
13
  uid="262598"
11
14
  :def-msg="{ placeholder: '发消息...' }"
12
- :show-header="true"
13
- :card-list="{dishes: false}"
14
- content-tye="markdown"
15
+ :show-header="false"
16
+ :card-list="{ dishes: true, personalForm: true }"
17
+ :tag-list="[
18
+ {
19
+ name: '用户信息',
20
+ value: 'personalForm',
21
+ type: 'chat',
22
+ msg: '#用户信息',
23
+ },
24
+ ]"
25
+ :need-log="true"
26
+ content-type="markdown"
27
+ first-msg="你好"
28
+ @log="handleLog"
15
29
  />
16
30
  </div>
17
31
  </template>
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,24 @@ 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
+ },
311
+ firstMsg: {
312
+ type: String,
313
+ default: '',
314
+ },
305
315
  });
306
316
 
307
- const Emits = defineEmits(['call']);
317
+ const Emits = defineEmits(['call', 'log']);
308
318
 
309
319
  const finalDefMsg = computed(() => {
310
320
  return {
@@ -344,17 +354,21 @@ onMounted(async () => {
344
354
  isFirst.value = false;
345
355
  } else {
346
356
  await createConv();
357
+ if (props.firstMsg) {
358
+ await chatConv([{ content: props.firstMsg, text: props.firstMsg }]);
359
+ }
347
360
  }
348
361
  scrollToEnd();
349
362
  });
350
363
 
351
364
  const createConv = async () => {
352
- isFirst.value = true;
353
365
  const res = await post(
354
366
  'https://api.coze.cn/v1/conversation/create',
355
367
  { bot_id: props.botId, connector_id: '999' },
356
368
  { ...chatOptions.value },
357
369
  );
370
+ isFirst.value = true;
371
+ turns.value = 0;
358
372
  console.log(res);
359
373
  if (res.code === 0 && res.data) {
360
374
  conversationId.value = res.data.id || '';
@@ -459,6 +473,13 @@ const chatConv = async (data) => {
459
473
  });
460
474
  historyList.value.push(uObj);
461
475
  isReq.value = '02';
476
+ turns.value += 1;
477
+ if (props.needLog) {
478
+ Emits('log', {
479
+ turns: turns.value,
480
+ info: uObj,
481
+ });
482
+ }
462
483
  const res = await fetch(
463
484
  `https://api.coze.cn/v3/chat?conversation_id=${conversationId.value}`,
464
485
  {
@@ -511,10 +532,12 @@ const chatConv = async (data) => {
511
532
  let buffer = '';
512
533
 
513
534
  const handlePersonalForm = () => {
514
- console.log('======= End ======', historyList.value);
535
+ console.log('======= End ======', historyList.value, isFirst.value);
515
536
  if (isFirst.value) {
516
537
  historyList.value[idx].extra.push({ showType: 'personalForm' });
517
538
  isFirst.value = false;
539
+
540
+ console.log('===============', historyList.value[idx]);
518
541
  }
519
542
  };
520
543
 
@@ -527,6 +550,12 @@ const chatConv = async (data) => {
527
550
  isReq.value = '00';
528
551
  historyList.value[idx].status = 'ended';
529
552
  handlePersonalForm();
553
+ if (props.needLog) {
554
+ Emits('log', {
555
+ turns: turns.value,
556
+ info: historyList.value[idx],
557
+ });
558
+ }
530
559
  scrollToEnd();
531
560
  break;
532
561
  }
@@ -681,7 +710,7 @@ const queryHistoryList = async () => {
681
710
  });
682
711
  }
683
712
 
684
- console.log('== history ==', historyList.value);
713
+ console.log('== history ==', historyList.value, finalCardList.value);
685
714
  };
686
715
 
687
716
  const queryBotInfo = async () => {