feat(knowledge): add channel support to knowledge entries and related components
- Introduced a new `channel` field in the Knowledge struct and associated request types to track the source channel (e.g., "web", "api", "browser_extension"). - Updated various frontend components to display channel information and enhance user experience with channel labels. - Enhanced localization files to support channel labels in English and Chinese. - Modified backend services and database migrations to accommodate the new channel feature, ensuring consistent tracking across knowledge entries. - Refactored related functions to integrate channel handling, improving overall knowledge management and context.
This commit is contained in:
@@ -400,6 +400,23 @@ const getDisplayTitle = () => {
|
||||
return props.details.title;
|
||||
};
|
||||
|
||||
const channelLabelMap: Record<string, string> = {
|
||||
web: 'knowledgeBase.channelWeb',
|
||||
api: 'knowledgeBase.channelApi',
|
||||
browser_extension: 'knowledgeBase.channelBrowserExtension',
|
||||
wechat: 'knowledgeBase.channelWechat',
|
||||
wecom: 'knowledgeBase.channelWecom',
|
||||
feishu: 'knowledgeBase.channelFeishu',
|
||||
dingtalk: 'knowledgeBase.channelDingtalk',
|
||||
slack: 'knowledgeBase.channelSlack',
|
||||
im: 'knowledgeBase.channelIm',
|
||||
};
|
||||
|
||||
const getChannelLabel = (channel: string) => {
|
||||
const key = channelLabelMap[channel];
|
||||
return key ? t(key) : t('knowledgeBase.channelUnknown');
|
||||
};
|
||||
|
||||
// 获取类型标签
|
||||
const getTypeLabel = () => {
|
||||
switch (props.details.type) {
|
||||
@@ -714,6 +731,9 @@ const handleDetailsScroll = () => {
|
||||
</div>
|
||||
<div class="meta-row">
|
||||
<span class="time"> {{ getTimeLabel() }}:{{ details.time }} </span>
|
||||
<t-tag v-if="details.channel && details.channel !== 'web'" size="small" variant="light" theme="warning" class="channel-tag">
|
||||
{{ getChannelLabel(details.channel) }}
|
||||
</t-tag>
|
||||
<div class="view-mode-buttons">
|
||||
<t-button
|
||||
v-if="canPreview()"
|
||||
@@ -1057,6 +1077,10 @@ const handleDetailsScroll = () => {
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.channel-tag {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.chunk-count {
|
||||
color: var(--td-brand-color);
|
||||
font-size: 12px;
|
||||
|
||||
@@ -28,6 +28,7 @@ export default function (knowledgeBaseId?: string) {
|
||||
total: 0,
|
||||
type: "",
|
||||
source: "",
|
||||
channel: "",
|
||||
file_type: "",
|
||||
chunkLoading: false,
|
||||
chunkLoadError: "",
|
||||
@@ -151,6 +152,7 @@ export default function (knowledgeBaseId?: string) {
|
||||
id: "",
|
||||
type: "",
|
||||
source: "",
|
||||
channel: "",
|
||||
file_type: "",
|
||||
chunkLoadError: "",
|
||||
});
|
||||
@@ -164,6 +166,7 @@ export default function (knowledgeBaseId?: string) {
|
||||
id: data.id,
|
||||
type: data.type || 'file',
|
||||
source: data.source || '',
|
||||
channel: data.channel || '',
|
||||
file_type: data.file_type || ''
|
||||
});
|
||||
}
|
||||
|
||||
@@ -129,6 +129,17 @@ export default {
|
||||
typeURL: 'URL',
|
||||
typeManual: 'Manual',
|
||||
typeFile: 'File',
|
||||
channelLabel: 'Source Channel',
|
||||
channelWeb: 'Web',
|
||||
channelApi: 'API',
|
||||
channelBrowserExtension: 'Browser Extension',
|
||||
channelWechat: 'WeChat',
|
||||
channelWecom: 'WeCom',
|
||||
channelFeishu: 'Feishu',
|
||||
channelDingtalk: 'DingTalk',
|
||||
channelSlack: 'Slack',
|
||||
channelIm: 'IM Channel',
|
||||
channelUnknown: 'Unknown',
|
||||
urlSource: 'Source URL',
|
||||
documentTitle: 'Document Title',
|
||||
webContent: 'Web Content',
|
||||
|
||||
@@ -128,6 +128,17 @@ export default {
|
||||
typeURL: "网页",
|
||||
typeManual: "手动创建",
|
||||
typeFile: "文件",
|
||||
channelLabel: "来源渠道",
|
||||
channelWeb: "网页端",
|
||||
channelApi: "API",
|
||||
channelBrowserExtension: "浏览器插件",
|
||||
channelWechat: "微信",
|
||||
channelWecom: "企业微信",
|
||||
channelFeishu: "飞书",
|
||||
channelDingtalk: "钉钉",
|
||||
channelSlack: "Slack",
|
||||
channelIm: "IM 渠道",
|
||||
channelUnknown: "未知",
|
||||
urlSource: "来源网址",
|
||||
documentTitle: "文档标题",
|
||||
webContent: "网页内容",
|
||||
|
||||
@@ -100,6 +100,7 @@ export interface DocumentInfoDocument {
|
||||
description?: string;
|
||||
type?: string;
|
||||
source?: string;
|
||||
channel?: string;
|
||||
file_name?: string;
|
||||
file_type?: string;
|
||||
file_size?: number;
|
||||
|
||||
@@ -32,6 +32,10 @@
|
||||
<span class="field-label">{{ $t('chat.documentSourceLabel') }}</span>
|
||||
<span class="field-value">{{ formatSource(doc) }}</span>
|
||||
</div>
|
||||
<div class="info-field" v-if="doc.channel && doc.channel !== 'web'">
|
||||
<span class="field-label">{{ $t('knowledgeBase.channelLabel') }}</span>
|
||||
<span class="field-value">{{ getChannelLabel(doc.channel) }}</span>
|
||||
</div>
|
||||
<div class="info-field" v-if="doc.file_name || doc.file_type || doc.file_size">
|
||||
<span class="field-label">{{ $t('chat.documentFileLabel') }}</span>
|
||||
<span class="field-value">
|
||||
@@ -84,6 +88,23 @@ const totalChunkCount = computed(() =>
|
||||
documents.value.reduce((sum, doc) => sum + (doc.chunk_count || 0), 0),
|
||||
);
|
||||
|
||||
const channelLabelMap: Record<string, string> = {
|
||||
web: 'knowledgeBase.channelWeb',
|
||||
api: 'knowledgeBase.channelApi',
|
||||
browser_extension: 'knowledgeBase.channelBrowserExtension',
|
||||
wechat: 'knowledgeBase.channelWechat',
|
||||
wecom: 'knowledgeBase.channelWecom',
|
||||
feishu: 'knowledgeBase.channelFeishu',
|
||||
dingtalk: 'knowledgeBase.channelDingtalk',
|
||||
slack: 'knowledgeBase.channelSlack',
|
||||
im: 'knowledgeBase.channelIm',
|
||||
};
|
||||
|
||||
const getChannelLabel = (channel: string) => {
|
||||
const key = channelLabelMap[channel];
|
||||
return key ? t(key) : t('knowledgeBase.channelUnknown');
|
||||
};
|
||||
|
||||
const formatSource = (doc: DocumentInfoDocument) => {
|
||||
if (doc.type && doc.source) {
|
||||
return `${doc.type} · ${doc.source}`;
|
||||
|
||||
@@ -280,6 +280,23 @@ const formatFileSize = (bytes?: number | string) => {
|
||||
return `${(n / (1024 * 1024)).toFixed(1)} MB`
|
||||
}
|
||||
|
||||
const channelLabelMap: Record<string, string> = {
|
||||
web: 'knowledgeBase.channelWeb',
|
||||
api: 'knowledgeBase.channelApi',
|
||||
browser_extension: 'knowledgeBase.channelBrowserExtension',
|
||||
wechat: 'knowledgeBase.channelWechat',
|
||||
wecom: 'knowledgeBase.channelWecom',
|
||||
feishu: 'knowledgeBase.channelFeishu',
|
||||
dingtalk: 'knowledgeBase.channelDingtalk',
|
||||
slack: 'knowledgeBase.channelSlack',
|
||||
im: 'knowledgeBase.channelIm',
|
||||
};
|
||||
|
||||
const getChannelLabel = (channel: string) => {
|
||||
const key = channelLabelMap[channel];
|
||||
return key ? t(key) : t('knowledgeBase.channelUnknown');
|
||||
};
|
||||
|
||||
// 获取知识条目的显示类型
|
||||
const getKnowledgeType = (item: any) => {
|
||||
if (item.type === 'url') {
|
||||
@@ -1923,6 +1940,7 @@ async function createNewSession(value: string): Promise<void> {
|
||||
</template>
|
||||
<div class="card-popover-meta">
|
||||
<span class="card-popover-time">{{ t('knowledgeBase.updatedAt') }}:{{ formatDocTime(hoveredCardItem.updated_at) }}</span>
|
||||
<span v-if="(hoveredCardItem as any).channel && (hoveredCardItem as any).channel !== 'web'" class="card-popover-channel">{{ getChannelLabel((hoveredCardItem as any).channel) }}</span>
|
||||
<span v-if="getTagName(hoveredCardItem.tag_id)" class="card-popover-tag">{{ getTagName(hoveredCardItem.tag_id) }}</span>
|
||||
<span class="card-popover-type">{{ getKnowledgeType(hoveredCardItem) }}</span>
|
||||
</div>
|
||||
@@ -3383,6 +3401,13 @@ async function createNewSession(value: string): Promise<void> {
|
||||
color: var(--td-text-color-secondary);
|
||||
}
|
||||
|
||||
.card-popover-channel {
|
||||
padding: 1px 6px;
|
||||
background: var(--td-warning-color-light);
|
||||
color: var(--td-warning-color);
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.card-popover-tag {
|
||||
padding: 1px 6px;
|
||||
background: var(--td-success-color-light);
|
||||
|
||||
Reference in New Issue
Block a user