Browse Source

feat:新增dify编辑名称和描述

hanyang 1 year ago
parent
commit
124e4b77dc

+ 72 - 72
src/3rd-libs/arco-vue-install-icon.js

@@ -316,7 +316,7 @@ export default function installArcoVue(app) {
   // app.use(IconCaretUp);
   // app.use(IconDoubleDown);
   // app.use(IconDoubleLeft);
-  app.use(IconDoubleRight);
+  // app.use(IconDoubleRight);
   // app.use(IconDoubleUp);
   // app.use(IconDownCircle);
   app.use(IconDown);
@@ -501,94 +501,94 @@ export default function installArcoVue(app) {
   // app.use(IconFaceSmileFill);
   // app.use(IconMoonFill);
   // app.use(IconPenFill);
-  // app.use(IconSunFill);
+  app.use(IconSunFill);
   app.use(IconApps);
-  // app.use(IconArchive);
-  // app.use(IconBarChart);
-  // app.use(IconBook);
+  app.use(IconArchive);
+  app.use(IconBarChart);
+  app.use(IconBook);
   app.use(IconBookmark);
-  // app.use(IconBranch);
+  app.use(IconBranch);
   app.use(IconBug);
   app.use(IconBulb);
   // app.use(IconCalendarClock);
   app.use(IconCalendar);
-  // app.use(IconCamera);
-  // app.use(IconCloud);
-  // app.use(IconCommand);
-  // app.use(IconCommon);
-  // app.use(IconCompass);
-  // app.use(IconComputer);
-  // app.use(IconCopyright);
-  // app.use(IconDashboard);
-  // app.use(IconDesktop);
-  // app.use(IconDice);
+  app.use(IconCamera);
+  app.use(IconCloud);
+  app.use(IconCommand);
+  app.use(IconCommon);
+  app.use(IconCompass);
+  app.use(IconComputer);
+  app.use(IconCopyright);
+  app.use(IconDashboard);
+  app.use(IconDesktop);
+  app.use(IconDice);
   // app.use(IconDragDotVertical);
   // app.use(IconDragDot);
-  // app.use(IconDriveFile);
-  // app.use(IconEar);
+  app.use(IconDriveFile);
+  app.use(IconEar);
   app.use(IconEmail);
-  // app.use(IconEmpty);
-  // app.use(IconExperiment);
-  // app.use(IconFileAudio);
-  // app.use(IconFileImage);
-  // app.use(IconFilePdf);
-  // app.use(IconFileVideo);
+  app.use(IconEmpty);
+  app.use(IconExperiment);
+  app.use(IconFileAudio);
+  app.use(IconFileImage);
+  app.use(IconFilePdf);
+  app.use(IconFileVideo);
   app.use(IconFile);
-  // app.use(IconFire);
-  // app.use(IconFolderAdd);
-  // app.use(IconFolderDelete);
-  // app.use(IconFolder);
-  // app.use(IconGift);
-  // app.use(IconIdcard);
-  // app.use(IconImageClose);
-  // app.use(IconImage);
-  // app.use(IconInteraction);
-  // app.use(IconLanguage);
-  // app.use(IconLayers);
-  // app.use(IconLayout);
-  // app.use(IconLoading);
-  // app.use(IconLocation);
+  app.use(IconFire);
+  app.use(IconFolderAdd);
+  app.use(IconFolderDelete);
+  app.use(IconFolder);
+  app.use(IconGift);
+  app.use(IconIdcard);
+  app.use(IconImageClose);
+  app.use(IconImage);
+  app.use(IconInteraction);
+  app.use(IconLanguage);
+  app.use(IconLayers);
+  app.use(IconLayout);
+  app.use(IconLoading);
+  app.use(IconLocation);
   app.use(IconLock);
-  // app.use(IconLoop);
-  // app.use(IconMan);
+  app.use(IconLoop);
+  app.use(IconMan);
   app.use(IconMenu);
-  // app.use(IconMindMapping);
-  // app.use(IconMobile);
-  // app.use(IconMoon);
-  // app.use(IconMosaic);
-  // app.use(IconNav);
-  // app.use(IconNotificationClose);
-  // app.use(IconNotification);
-  // app.use(IconPalette);
-  // app.use(IconPen);
-  // app.use(IconPhone);
-  // app.use(IconPrinter);
-  // app.use(IconPublic);
-  // app.use(IconPushpin);
-  // app.use(IconQrcode);
+  app.use(IconMindMapping);
+  app.use(IconMobile);
+  app.use(IconMoon);
+  app.use(IconMosaic);
+  app.use(IconNav);
+  app.use(IconNotificationClose);
+  app.use(IconNotification);
+  app.use(IconPalette);
+  app.use(IconPen);
+  app.use(IconPhone);
+  app.use(IconPrinter);
+  app.use(IconPublic);
+  app.use(IconPushpin);
+  app.use(IconQrcode);
   app.use(IconRelation);
-  // app.use(IconRobotAdd);
+  app.use(IconRobotAdd);
   app.use(IconRobot);
-  // app.use(IconSafe);
-  // app.use(IconSchedule);
-  // app.use(IconShake);
-  // app.use(IconSkin);
-  // app.use(IconStamp);
+  app.use(IconSafe);
+  app.use(IconSchedule);
+  app.use(IconShake);
+  app.use(IconSkin);
+  app.use(IconStamp);
   app.use(IconStorage);
-  // app.use(IconSubscribeAdd);
-  // app.use(IconSubscribe);
-  // app.use(IconSubscribed);
-  // app.use(IconSun);
-  // app.use(IconTag);
+  app.use(IconSubscribeAdd);
+  app.use(IconSubscribe);
+  app.use(IconSubscribed);
+  app.use(IconSun);
+  app.use(IconTag);
   app.use(IconTags);
-  // app.use(IconThunderbolt);
+  app.use(IconThunderbolt);
   app.use(IconTool);
-  // app.use(IconTrophy);
-  // app.use(IconUnlock);
-  // app.use(IconUserAdd);
-  // app.use(IconUserGroup);
+  app.use(IconTrophy);
+  app.use(IconUnlock);
+  app.use(IconUserAdd);
+  app.use(IconUserGroup);
   app.use(IconUser);
-  // app.use(IconVideoCamera);
-  // app.use(IconWifi);
+  app.use(IconVideoCamera);
+  app.use(IconWifi);
   // app.use(IconWoman);
 }

+ 12 - 5
src/apis/intelligent.js

@@ -136,13 +136,20 @@ export function changeDialogStatus(id, status) {
  * @param {string} id 智能体ID
  * @param {string} icon 图标名称
  * */
-export function updateOwnIntelligentIcon(id, icon) {
+export function updateOwnIntelligentIcon(id, icon, name = undefined, description = undefined) {
+  const data = {
+    id,
+    icon
+  };
+  if (name) {
+    data.name = name;
+  }
+  if (description) {
+    data.description = description;
+  }
   return request({
     url: `/api/dialog/update_icon`,
     method: 'put',
-    data: {
-      id,
-      icon
-    }
+    data
   });
 }

+ 1 - 1
src/apis/rgflow-dify.js

@@ -28,7 +28,7 @@ export function deleteDify(id) {
  * */
 export function updateDify(id, data) {
   return request({
-    url: `/console/api/apps/${id}`,
+    url: `/dify/console/api/apps/${id}`,
     method: 'put',
     data
   });

+ 1 - 1
src/modules/common/CardItem.vue

@@ -79,7 +79,7 @@ const handleClickIcon = () => {
 .card-des {
   display: -webkit-box;
   overflow: hidden;
-  height: 60px;
+  height: 68px;
   margin-top: 5px;
   font-size: 12px;
   line-height: 16px;

+ 65 - 4
src/modules/intelligent/MessageBody.vue

@@ -55,6 +55,12 @@
           <div class="tools" v-if="!item.online">
             <icon-settings :style="{ cursor: 'pointer' }" @click.stop="editIntelligent(item)" />
             <icon-delete :style="{ cursor: 'pointer' }" @click.stop="deleteIntelligent(item)" />
+            <!-- ragflow的修改不支持该接口 -->
+            <icon-edit
+              v-if="item.agentType !== '1'"
+              :style="{ cursor: 'pointer' }"
+              @click.stop="updateIntelligent(item)"
+            />
           </div>
         </div>
       </template>
@@ -68,6 +74,18 @@
   <a-empty v-if="!moke_data.length"></a-empty>
   <ManageTags v-model:visible="visible" :labels="label_list" @updateLabels="updateLabels"></ManageTags>
   <DeleteModal :visible.sync="delete_visible" @ok="deleteModalOk" @cancel="delete_visible = false" />
+  <ModelUpdateItem
+    v-if="show_model_item"
+    :show_model_item="show_model_item"
+    :target_intell_type="update_model_data.mode"
+    :target_icon="update_model_data.icon"
+    :name="update_model_data.name"
+    :description="update_model_data.description"
+    :id="update_model_data.id"
+    @closeModel="closeUpdateModel"
+    @select_icon="selectIcon"
+    @updateIntelligentList="updateIntelligentList"
+  ></ModelUpdateItem>
 </template>
 
 <script setup>
@@ -77,6 +95,7 @@ import { Message } from '../../3rd-libs/arco-vue-libs';
 import CardItem from '../common/CardItem.vue';
 import ManageTags from './ManageTags.vue';
 import DeleteModal from '../../components/DeleteModal.vue';
+import ModelUpdateItem from './ModelUpdateItem.vue';
 import { getIconIntelligent, getImageIntelligent } from '../common/icon-map.js';
 import LabelSelected from './LabelSelected.vue';
 import { getDialogListForFilter } from '../../apis/intelligent';
@@ -90,6 +109,8 @@ import { dialogType } from '../../views/manage/common';
 import { funcThrottle } from '../../utils/utils';
 import { getLabelList, addLabelToDialog, changeDialogStatus, deleteDialog } from '../../apis/intelligent';
 import { deleteDify, deleteRgFlow } from '../../apis/rgflow-dify';
+import { useI18n } from 'vue-i18n';
+const { t } = useI18n();
 
 const moke_data = ref([
   // {
@@ -120,6 +141,9 @@ const loading_data = ref(false);
 // 删除弹窗
 const delete_visible = ref(false);
 const delete_intelligent_item = ref(null);
+// 编辑弹窗
+const show_model_item = ref(false);
+const update_model_data = ref({});
 
 const getDialog = async () => {
   if (pages.current == 1) {
@@ -170,17 +194,37 @@ const openManageTags = () => {
 const editIntelligent = (item) => {
   bus_intelligentEdit.emit(item);
 };
+
+const updateIntelligentList = () => {
+  bus_intelligentSearch.emit('');
+};
 const deleteIntelligent = (item) => {
   delete_intelligent_item.value = item;
   delete_visible.value = true;
 };
+
+const deleteItem = async (id) => {
+  const response = await deleteDialog(delete_intelligent_item.value.id);
+  console.log(response);
+  if (response.code / 1 == 200) {
+    Message.success(t('management.delete_success'));
+  } else {
+    Message.error(t('management.delete_fail'));
+  }
+};
 const deleteModalOk = async () => {
   if (delete_intelligent_item.value.agentType == dialogType.DIFY) {
-    await deleteDify(delete_intelligent_item.value.id);
-    const response = await deleteDialog(delete_intelligent_item.value.id);
-    if (response.code == 200) {
-      Message.success(t('management.delete_success'));
+    try {
+      const res = await deleteDify(delete_intelligent_item.value.id);
+      console.log(res);
+      await deleteItem(delete_intelligent_item.value.id);
+    } catch (e) {
+      console.log(e);
+      if (e.status / 1 === 404) {
+        await deleteItem(delete_intelligent_item.value.id);
+      }
     }
+
     // TODO:刷新页面
   } else if (delete_intelligent_item.value.agentType == dialogType.RAGFLOW) {
     const data = {
@@ -198,6 +242,23 @@ const deleteModalOk = async () => {
   delete_visible.value = false;
 };
 
+const updateIntelligent = (item) => {
+  show_model_item.value = true;
+  console.log(item, 999);
+  update_model_data.value = {
+    name: item.name,
+    mode: item.mode,
+    icon: item.icon,
+    id: item.id,
+    description: item.description
+  };
+};
+const closeUpdateModel = () => {
+  show_model_item.value = false;
+};
+const selectIcon = () => {
+  show_select_icon.value = true;
+};
 // 获取标签列表
 const getLabels = async () => {
   try {

+ 0 - 265
src/modules/intelligent/ModalSelectIcon.vue

@@ -48,271 +48,6 @@ const icons = ref(icons_intell);
 //     name: 'intellFrame1',
 //     group: 1
 //   },
-//   {
-//     id: 2,
-//     name: 'intellFrame2',
-//     group: 1
-//   },
-//   {
-//     id: 3,
-//     name: 'intellFrame3',
-//     group: 1
-//   },
-//   {
-//     id: 4,
-//     name: 'intellFrame4',
-//     group: 1
-//   },
-//   {
-//     id: 19,
-//     name: 'intellFrame19',
-//     group: 1
-//   },
-//   {
-//     id: 20,
-//     name: 'intellFrame20',
-//     group: 1
-//   },
-//   {
-//     id: 21,
-//     name: 'intellFrame21',
-//     group: 1
-//   },
-//   {
-//     id: 22,
-//     name: 'intellFrame22',
-//     group: 1
-//   },
-//   {
-//     id: 23,
-//     name: 'intellFrame23',
-//     group: 1
-//   },
-//   {
-//     id: 6,
-//     name: 'intellFrame6',
-//     group: 2
-//   },
-//   {
-//     id: 5,
-//     name: 'intellFrame5',
-//     group: 2
-//   },
-//   {
-//     id: 24,
-//     name: 'intellFrame24',
-//     group: 2
-//   },
-//   {
-//     id: 25,
-//     name: 'intellFrame25',
-//     group: 2
-//   },
-//   {
-//     id: 26,
-//     name: 'intellFrame26',
-//     group: 2
-//   },
-//   {
-//     id: 27,
-//     name: 'intellFrame27',
-//     group: 2
-//   },
-//   {
-//     id: 28,
-//     name: 'intellFrame28',
-//     group: 2
-//   },
-//   {
-//     id: 29,
-//     name: 'intellFrame29',
-//     group: 2
-//   },
-//   {
-//     id: 30,
-//     name: 'intellFrame30',
-//     group: 2
-//   },
-//   {
-//     id: 31,
-//     name: 'intellFrame31',
-//     group: 3
-//   },
-//   {
-//     id: 32,
-//     name: 'intellFrame32',
-//     group: 3
-//   },
-//   {
-//     id: 33,
-//     name: 'intellFrame33',
-//     group: 3
-//   },
-//   {
-//     id: 34,
-//     name: 'intellFrame34',
-//     group: 3
-//   },
-//   {
-//     id: 35,
-//     name: 'intellFrame35',
-//     group: 3
-//   },
-//   {
-//     id: 36,
-//     name: 'intellFrame36',
-//     group: 3
-//   },
-//   {
-//     id: 37,
-//     name: 'intellFrame37',
-//     group: 3
-//   },
-//   {
-//     id: 38,
-//     name: 'intellFrame38',
-//     group: 3
-//   },
-//   {
-//     id: 39,
-//     name: 'intellFrame39',
-//     group: 3
-//   },
-//   {
-//     id: 40,
-//     name: 'intellFrame40',
-//     group: 4
-//   },
-//   {
-//     id: 41,
-//     name: 'intellFrame41',
-//     group: 4
-//   },
-//   {
-//     id: 42,
-//     name: 'intellFrame42',
-//     group: 4
-//   },
-//   {
-//     id: 43,
-//     name: 'intellFrame43',
-//     group: 4
-//   },
-//   {
-//     id: 44,
-//     name: 'intellFrame44',
-//     group: 4
-//   },
-//   {
-//     id: 45,
-//     name: 'intellFrame45',
-//     group: 4
-//   },
-//   {
-//     id: 46,
-//     name: 'intellFrame46',
-//     group: 4
-//   },
-//   {
-//     id: 47,
-//     name: 'intellFrame47',
-//     group: 4
-//   },
-//   {
-//     id: 48,
-//     name: 'intellFrame48',
-//     group: 4
-//   },
-//   {
-//     id: 50,
-//     name: 'intellFrame50',
-//     group: 5
-//   },
-//   {
-//     id: 51,
-//     name: 'intellFrame51',
-//     group: 5
-//   },
-//   {
-//     id: 52,
-//     name: 'intellFrame52',
-//     group: 5
-//   },
-//   {
-//     id: 53,
-//     name: 'intellFrame53',
-//     group: 5
-//   },
-//   {
-//     id: 54,
-//     name: 'intellFrame54',
-//     group: 5
-//   },
-//   {
-//     id: 55,
-//     name: 'intellFrame55',
-//     group: 5
-//   },
-//   {
-//     id: 56,
-//     name: 'intellFrame56',
-//     group: 5
-//   },
-//   {
-//     id: 57,
-//     name: 'intellFrame57',
-//     group: 5
-//   },
-//   {
-//     id: 58,
-//     name: 'intellFrame58',
-//     group: 5
-//   },
-//   {
-//     id: 60,
-//     name: 'intellFrame60',
-//     group: 6
-//   },
-//   {
-//     id: 61,
-//     name: 'intellFrame61',
-//     group: 6
-//   },
-//   {
-//     id: 62,
-//     name: 'intellFrame62',
-//     group: 6
-//   },
-//   {
-//     id: 63,
-//     name: 'intellFrame63',
-//     group: 6
-//   },
-//   {
-//     id: 64,
-//     name: 'intellFrame64',
-//     group: 6
-//   },
-//   {
-//     id: 65,
-//     name: 'intellFrame65',
-//     group: 6
-//   },
-//   {
-//     id: 66,
-//     name: 'intellFrame66',
-//     group: 6
-//   },
-//   {
-//     id: 67,
-//     name: 'intellFrame67',
-//     group: 6
-//   },
-//   {
-//     id: 68,
-//     name: 'intellFrame68',
-//     group: 6
-//   }
 // ]);
 
 const target_icon_id = ref(icons.value[0].id);

+ 167 - 0
src/modules/intelligent/ModelUpdateItem.vue

@@ -0,0 +1,167 @@
+<template>
+  <a-modal v-model:visible="show_modal" :align-center="false" top="15vh" @ok="handleOk" @cancel="handleCancel">
+    <template #title> {{ $t('management.update_intelligent_title') }}</template>
+    <div class="section">
+      <div class="form-item">
+        <div class="label">{{ $t('management.label_name') }}</div>
+        <div class="value">
+          <img class="icon" :src="getIconIntelligent(icon_name)" alt="" @click="handleSelectIcon" />
+          <a-input v-model="form.name" :placeholder="$t('management.input_placeholder')" />
+        </div>
+      </div>
+      <div class="form-item">
+        <div class="label">{{ $t('management.label_desc') }}</div>
+        <a-textarea
+          v-model="form.description"
+          :placeholder="$t('management.label_desc')"
+          :auto-size="{ minRows: 2, maxRows: 5 }"
+        />
+      </div>
+    </div>
+  </a-modal>
+  <ModelSelectIcon
+    v-model:show_select_icon="show_select_icon"
+    :target_icon="target_icon"
+    @sendIcon="sendIcon"
+  ></ModelSelectIcon>
+</template>
+
+<script setup>
+import { ref, computed } from 'vue';
+import { useRouter } from 'vue-router';
+import { createDify, updateDify } from '../../apis/rgflow-dify';
+import { createDialog, updateOwnIntelligentIcon } from '../../apis/intelligent';
+import { dialogType } from '../../views/manage/common';
+import { getIconIntelligent } from '../common/icon-map.js';
+import { Message } from '../../3rd-libs/arco-vue-libs';
+import { useI18n } from 'vue-i18n';
+import ModelSelectIcon from './ModalSelectIcon.vue';
+
+const { t } = useI18n();
+
+const props = defineProps({
+  show_model_item: {
+    type: Boolean,
+    default: false
+  },
+  target_intell_type: {
+    type: String,
+    default: 'advanced-chat'
+  },
+  target_icon: {
+    type: String,
+    default: 'intellFrame1'
+  },
+  name: {
+    type: String,
+    default: ''
+  },
+  description: {
+    type: String,
+    default: ''
+  },
+  id: {
+    type: String,
+    default: ''
+  }
+});
+const router = useRouter();
+
+const emit = defineEmits(['closeModel', 'select_icon', 'updateIntelligentList', 'clearSelectIcon']);
+
+const formInit = {
+  name: '',
+  description: ''
+};
+const form = ref(Object.assign({}, formInit));
+form.value = Object.assign({}, formInit, {
+  name: props.name,
+  description: props.description
+});
+const show_select_icon = ref(false);
+const icon_name = ref(props.target_icon);
+
+let show_modal = computed(() => props.show_model_item);
+
+const sendIcon = (icon) => {
+  icon_name.value = icon;
+};
+const handleOk = async () => {
+  const edit_id = props.id;
+  const data = {
+    name: form.value.name,
+    description: form.value.description,
+    use_icon_as_answer_icon: false
+  };
+
+  // if (icon_name.value !== props.target_icon) {
+  //   await updateOwnIntelligentIcon(edit_id, icon_name.value);
+  // }
+  const res = await updateDify(edit_id, data);
+  if (res) {
+    const response = await updateOwnIntelligentIcon(edit_id, icon_name.value, data.name, data.description);
+    console.log(response, 1111);
+    if (response.code == 200) {
+      Message.success(t('management.edit_success'));
+      emit('updateIntelligentList');
+      handleCancel();
+    } else {
+      Message.error(t('management.edit_fail'));
+    }
+  } else {
+    Message.error(t('management.edit_fail'));
+  }
+};
+// const createOwnDialog = async (data) => {
+//   try {
+//     const res = await createDialog(data);
+//     if (res.code == 200) {
+//       handleCancel();
+//       emit('updateIntelligentList');
+//       // 新建成功
+//       Message.success(t('management.create_success'));
+//       // 新建成功进入dify详情页F
+//       router.push({ path: '/intelligent/detail', query: { id: data.id, name: data.name, mode: data.mode } });
+//     } else {
+//       Message.error(t('management.create_fail'));
+//     }
+//   } catch (err) {
+//     console.log(t('management.create_fail'), err);
+//   }
+// };
+const handleCancel = () => {
+  form.value = Object.assign({}, formInit);
+  emit('closeModel', false);
+};
+const handleSelectIcon = () => {
+  // emit('select_icon');
+  show_select_icon.value = true;
+};
+</script>
+<style scoped lang="css">
+.section {
+  padding: 0 20px;
+}
+.form-item {
+  display: flex;
+  flex-direction: column;
+  gap: 10px;
+  margin-top: 20px;
+}
+.value {
+  display: flex;
+  align-items: center;
+  gap: 10px;
+}
+.value .icon {
+  width: 44px;
+  cursor: pointer;
+}
+.arco-input-wrapper {
+  height: 32px;
+  background-color: var(--color-fill-2);
+}
+.arco-input-wrapper:hover {
+  background-color: var(--color-fill-3);
+}
+</style>

+ 12 - 1
src/views/conversation/ConversationChatContainer.vue

@@ -107,6 +107,7 @@ import useInputGetOptions from './use-input-get-options';
 import useScroll2Bottom from './use-scroll-bottom';
 import { IconEye } from '@arco-design/web-vue/es/icon';
 import { file, files } from 'jszip';
+import { getFileType } from '../../modules/form-dynamic/file-accept';
 
 const props = defineProps({
   /**
@@ -699,7 +700,17 @@ const handleInputSubmit = async (options) => {
     try {
       const menu_id = current_menu_id.value;
       const uploadResult = await uploadFileByAgentInfo(agent_id, chat_id, ask_files, menu_id);
-      files_response = uploadResult;
+      if (uploadResult.length) {
+        files_response = uploadResult.map((item) => {
+          return {
+            ...item,
+            url: '',
+            type: getFileType(item),
+            transfer_method: 'local_file',
+            upload_file_id: item.id
+          };
+        });
+      }
       // if (uploadResult.code / 1 === 200) {
       //   // 文件上传成功
       //   files_response = uploadResult.data;

+ 1 - 0
vite.config.mjs

@@ -35,6 +35,7 @@ export default defineConfig(({ mode }) => {
       proxy: {
         '/api/': {
           target: 'http://smartai.com:8401',
+          // target: 'http://192.168.20.119:9303',
           changeOrigin: true,
           secure: false,
           ws: true,