refactor: 统一标签列表渲染逻辑,移除重复的未分类标签处理代码
This commit is contained in:
@@ -91,14 +91,10 @@ const tagMap = computed<Record<string, any>>(() => {
|
||||
return map;
|
||||
});
|
||||
const sidebarCategoryCount = computed(() => tagList.value.length);
|
||||
// Filter out the untagged pseudo-tag from regular tags
|
||||
const regularTags = computed(() => tagList.value.filter((tag) => tag.id !== UNTAGGED_TAG_ID));
|
||||
// Get the untagged pseudo-tag from the list
|
||||
const untaggedTag = computed(() => tagList.value.find((tag) => tag.id === UNTAGGED_TAG_ID));
|
||||
const filteredTags = computed(() => {
|
||||
const query = tagSearchQuery.value.trim().toLowerCase();
|
||||
if (!query) return regularTags.value;
|
||||
return regularTags.value.filter((tag) => (tag.name || '').toLowerCase().includes(query));
|
||||
if (!query) return tagList.value;
|
||||
return tagList.value.filter((tag) => (tag.name || '').toLowerCase().includes(query));
|
||||
});
|
||||
|
||||
const editingTagInputRefs = new Map<string, TagInputInstance | null>();
|
||||
@@ -1003,18 +999,6 @@ async function createNewSession(value: string): Promise<void> {
|
||||
</div>
|
||||
<t-loading :loading="tagLoading" size="small">
|
||||
<div class="tag-list">
|
||||
<div
|
||||
v-if="untaggedTag"
|
||||
class="tag-list-item"
|
||||
:class="{ active: selectedTagId === UNTAGGED_TAG_ID }"
|
||||
@click="handleUntaggedClick"
|
||||
>
|
||||
<div class="tag-list-left">
|
||||
<t-icon name="folder" size="18px" />
|
||||
<span>{{ $t('knowledgeBase.untagged') || '未分类' }}</span>
|
||||
</div>
|
||||
<span class="tag-count">{{ untaggedTag.knowledge_count || 0 }}</span>
|
||||
</div>
|
||||
<div v-if="creatingTag" class="tag-list-item tag-editing" @click.stop>
|
||||
<div class="tag-list-left">
|
||||
<t-icon name="folder" size="18px" />
|
||||
@@ -1058,12 +1042,16 @@ async function createNewSession(value: string): Promise<void> {
|
||||
v-for="tag in filteredTags"
|
||||
:key="tag.id"
|
||||
class="tag-list-item"
|
||||
:class="{ active: selectedTagId === tag.id, editing: editingTagId === tag.id }"
|
||||
@click="handleTagRowClick(tag.id)"
|
||||
:class="{ active: selectedTagId === tag.id, editing: editingTagId === tag.id && tag.id !== UNTAGGED_TAG_ID }"
|
||||
@click="tag.id === UNTAGGED_TAG_ID ? handleUntaggedClick() : handleTagRowClick(tag.id)"
|
||||
>
|
||||
<div class="tag-list-left">
|
||||
<t-icon name="folder" size="18px" />
|
||||
<template v-if="editingTagId === tag.id">
|
||||
<!-- Untagged pseudo-tag: show translated name, no editing -->
|
||||
<template v-if="tag.id === UNTAGGED_TAG_ID">
|
||||
<span class="tag-name">{{ $t('knowledgeBase.untagged') || '未分类' }}</span>
|
||||
</template>
|
||||
<template v-else-if="editingTagId === tag.id">
|
||||
<div class="tag-edit-input" @click.stop>
|
||||
<t-input
|
||||
:ref="setEditingTagInputRefByTag(tag.id)"
|
||||
@@ -1081,46 +1069,54 @@ async function createNewSession(value: string): Promise<void> {
|
||||
</div>
|
||||
<div class="tag-list-right">
|
||||
<span class="tag-count">{{ tag.knowledge_count || 0 }}</span>
|
||||
<div v-if="editingTagId === tag.id" class="tag-inline-actions" @click.stop>
|
||||
<t-button
|
||||
variant="text"
|
||||
theme="default"
|
||||
size="small"
|
||||
class="tag-action-btn confirm"
|
||||
:loading="editingTagSubmitting"
|
||||
@click.stop="submitEditTag"
|
||||
>
|
||||
<t-icon name="check" size="16px" />
|
||||
</t-button>
|
||||
<t-button
|
||||
variant="text"
|
||||
theme="default"
|
||||
size="small"
|
||||
class="tag-action-btn cancel"
|
||||
@click.stop="cancelEditTag"
|
||||
>
|
||||
<t-icon name="close" size="16px" />
|
||||
</t-button>
|
||||
</div>
|
||||
<div v-else class="tag-more" @click.stop>
|
||||
<t-popup trigger="click" placement="top-right" overlayClassName="tag-more-popup">
|
||||
<div class="tag-more-btn">
|
||||
<t-icon name="more" size="14px" />
|
||||
</div>
|
||||
<template #content>
|
||||
<div class="tag-menu">
|
||||
<div class="tag-menu-item" @click="startEditTag(tag)">
|
||||
<t-icon class="menu-icon" name="edit" />
|
||||
<span>{{ $t('knowledgeBase.tagEditAction') }}</span>
|
||||
</div>
|
||||
<div class="tag-menu-item danger" @click="confirmDeleteTag(tag)">
|
||||
<t-icon class="menu-icon" name="delete" />
|
||||
<span>{{ $t('knowledgeBase.tagDeleteAction') }}</span>
|
||||
</div>
|
||||
<!-- Untagged pseudo-tag: no edit/delete actions -->
|
||||
<template v-if="tag.id === UNTAGGED_TAG_ID">
|
||||
<!-- Empty placeholder for alignment -->
|
||||
</template>
|
||||
<template v-else-if="editingTagId === tag.id">
|
||||
<div class="tag-inline-actions" @click.stop>
|
||||
<t-button
|
||||
variant="text"
|
||||
theme="default"
|
||||
size="small"
|
||||
class="tag-action-btn confirm"
|
||||
:loading="editingTagSubmitting"
|
||||
@click.stop="submitEditTag"
|
||||
>
|
||||
<t-icon name="check" size="16px" />
|
||||
</t-button>
|
||||
<t-button
|
||||
variant="text"
|
||||
theme="default"
|
||||
size="small"
|
||||
class="tag-action-btn cancel"
|
||||
@click.stop="cancelEditTag"
|
||||
>
|
||||
<t-icon name="close" size="16px" />
|
||||
</t-button>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else>
|
||||
<div class="tag-more" @click.stop>
|
||||
<t-popup trigger="click" placement="top-right" overlayClassName="tag-more-popup">
|
||||
<div class="tag-more-btn">
|
||||
<t-icon name="more" size="14px" />
|
||||
</div>
|
||||
</template>
|
||||
</t-popup>
|
||||
</div>
|
||||
<template #content>
|
||||
<div class="tag-menu">
|
||||
<div class="tag-menu-item" @click="startEditTag(tag)">
|
||||
<t-icon class="menu-icon" name="edit" />
|
||||
<span>{{ $t('knowledgeBase.tagEditAction') }}</span>
|
||||
</div>
|
||||
<div class="tag-menu-item danger" @click="confirmDeleteTag(tag)">
|
||||
<t-icon class="menu-icon" name="delete" />
|
||||
<span>{{ $t('knowledgeBase.tagDeleteAction') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</t-popup>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -140,22 +140,6 @@
|
||||
</div>
|
||||
<t-loading :loading="tagLoading" size="small">
|
||||
<div ref="tagListRef" class="faq-tag-list" @scroll="handleTagListScroll">
|
||||
<div
|
||||
class="faq-tag-item"
|
||||
:class="{ active: selectedTagId === UNTAGGED_FILTER }"
|
||||
@click="handleUntaggedClick"
|
||||
>
|
||||
<div class="faq-tag-left">
|
||||
<t-icon name="folder" size="18px" />
|
||||
<span>{{ $t('knowledgeBase.untagged') }}</span>
|
||||
</div>
|
||||
<div class="faq-tag-right">
|
||||
<span class="faq-tag-count">{{ untaggedFAQCount }}</span>
|
||||
<!-- Placeholder for alignment with other tags that have more menu -->
|
||||
<div class="tag-more-placeholder"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="creatingTag" class="faq-tag-item tag-editing" @click.stop>
|
||||
<div class="faq-tag-left">
|
||||
<t-icon name="folder" size="18px" />
|
||||
@@ -199,12 +183,16 @@
|
||||
v-for="tag in filteredTags"
|
||||
:key="tag.id"
|
||||
class="faq-tag-item"
|
||||
:class="{ active: selectedTagId === tag.id, editing: editingTagId === tag.id }"
|
||||
@click="handleTagRowClick(tag.id)"
|
||||
:class="{ active: selectedTagId === tag.id, editing: editingTagId === tag.id && tag.id !== UNTAGGED_FILTER }"
|
||||
@click="tag.id === UNTAGGED_FILTER ? handleUntaggedClick() : handleTagRowClick(tag.id)"
|
||||
>
|
||||
<div class="faq-tag-left">
|
||||
<t-icon name="folder" size="18px" />
|
||||
<template v-if="editingTagId === tag.id">
|
||||
<!-- Untagged pseudo-tag: show translated name, no editing -->
|
||||
<template v-if="tag.id === UNTAGGED_FILTER">
|
||||
<span class="tag-name">{{ $t('knowledgeBase.untagged') }}</span>
|
||||
</template>
|
||||
<template v-else-if="editingTagId === tag.id">
|
||||
<div class="tag-edit-input" @click.stop>
|
||||
<t-input
|
||||
:ref="setEditingTagInputRefByTag(tag.id)"
|
||||
@@ -222,46 +210,54 @@
|
||||
</div>
|
||||
<div class="faq-tag-right">
|
||||
<span class="faq-tag-count">{{ tag.chunk_count || 0 }}</span>
|
||||
<div v-if="editingTagId === tag.id" class="tag-inline-actions" @click.stop>
|
||||
<t-button
|
||||
variant="text"
|
||||
theme="default"
|
||||
size="small"
|
||||
class="tag-action-btn confirm"
|
||||
:loading="editingTagSubmitting"
|
||||
@click.stop="submitEditTag"
|
||||
>
|
||||
<t-icon name="check" size="16px" />
|
||||
</t-button>
|
||||
<t-button
|
||||
variant="text"
|
||||
theme="default"
|
||||
size="small"
|
||||
class="tag-action-btn cancel"
|
||||
@click.stop="cancelEditTag"
|
||||
>
|
||||
<t-icon name="close" size="16px" />
|
||||
</t-button>
|
||||
</div>
|
||||
<div v-else class="tag-more" @click.stop>
|
||||
<t-popup trigger="click" placement="top-right" overlayClassName="tag-more-popup">
|
||||
<div class="tag-more-btn">
|
||||
<t-icon name="more" size="14px" />
|
||||
</div>
|
||||
<template #content>
|
||||
<div class="tag-menu">
|
||||
<div class="tag-menu-item" @click="startEditTag(tag)">
|
||||
<t-icon class="menu-icon" name="edit" />
|
||||
<span>{{ $t('knowledgeBase.tagEditAction') }}</span>
|
||||
</div>
|
||||
<div class="tag-menu-item danger" @click="confirmDeleteTag(tag)">
|
||||
<t-icon class="menu-icon" name="delete" />
|
||||
<span>{{ $t('knowledgeBase.tagDeleteAction') }}</span>
|
||||
</div>
|
||||
<!-- Untagged pseudo-tag: no edit/delete actions, just a placeholder -->
|
||||
<template v-if="tag.id === UNTAGGED_FILTER">
|
||||
<div class="tag-more-placeholder"></div>
|
||||
</template>
|
||||
<template v-else-if="editingTagId === tag.id">
|
||||
<div class="tag-inline-actions" @click.stop>
|
||||
<t-button
|
||||
variant="text"
|
||||
theme="default"
|
||||
size="small"
|
||||
class="tag-action-btn confirm"
|
||||
:loading="editingTagSubmitting"
|
||||
@click.stop="submitEditTag"
|
||||
>
|
||||
<t-icon name="check" size="16px" />
|
||||
</t-button>
|
||||
<t-button
|
||||
variant="text"
|
||||
theme="default"
|
||||
size="small"
|
||||
class="tag-action-btn cancel"
|
||||
@click.stop="cancelEditTag"
|
||||
>
|
||||
<t-icon name="close" size="16px" />
|
||||
</t-button>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else>
|
||||
<div class="tag-more" @click.stop>
|
||||
<t-popup trigger="click" placement="top-right" overlayClassName="tag-more-popup">
|
||||
<div class="tag-more-btn">
|
||||
<t-icon name="more" size="14px" />
|
||||
</div>
|
||||
</template>
|
||||
</t-popup>
|
||||
</div>
|
||||
<template #content>
|
||||
<div class="tag-menu">
|
||||
<div class="tag-menu-item" @click="startEditTag(tag)">
|
||||
<t-icon class="menu-icon" name="edit" />
|
||||
<span>{{ $t('knowledgeBase.tagEditAction') }}</span>
|
||||
</div>
|
||||
<div class="tag-menu-item danger" @click="confirmDeleteTag(tag)">
|
||||
<t-icon class="menu-icon" name="delete" />
|
||||
<span>{{ $t('knowledgeBase.tagDeleteAction') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</t-popup>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -1218,10 +1214,6 @@ const newTagName = ref('')
|
||||
const editingTagId = ref<string | null>(null)
|
||||
const editingTagName = ref('')
|
||||
const editingTagSubmitting = ref(false)
|
||||
const tagDropdownOptions = computed(() => [
|
||||
{ content: t('knowledgeBase.untagged') || '未分类', value: '' },
|
||||
...tagList.value.map((tag: any) => ({ content: tag.name, value: tag.id })),
|
||||
])
|
||||
const tagMap = computed<Record<string, any>>(() => {
|
||||
const map: Record<string, any> = {}
|
||||
tagList.value.forEach((tag) => {
|
||||
@@ -1229,17 +1221,17 @@ const tagMap = computed<Record<string, any>>(() => {
|
||||
})
|
||||
return map
|
||||
})
|
||||
// Filter out the __untagged__ pseudo-tag for tag select options (when assigning tags)
|
||||
const regularTags = computed(() => tagList.value.filter((tag) => tag.id !== UNTAGGED_FILTER))
|
||||
const tagDropdownOptions = computed(() => [
|
||||
{ content: t('knowledgeBase.untagged') || '未分类', value: '' },
|
||||
...regularTags.value.map((tag: any) => ({ content: tag.name, value: tag.id })),
|
||||
])
|
||||
const tagSelectOptions = computed(() => [
|
||||
{ label: t('knowledgeBase.untagged') || '未分类', value: '' },
|
||||
...tagList.value.map((tag: any) => ({ label: tag.name, value: tag.id })),
|
||||
...regularTags.value.map((tag: any) => ({ label: tag.name, value: tag.id })),
|
||||
])
|
||||
const sidebarCategoryCount = computed(() => tagList.value.length + 1)
|
||||
const assignedFAQCount = computed(() =>
|
||||
tagList.value.reduce((sum, tag) => sum + (tag.chunk_count || 0), 0),
|
||||
)
|
||||
const untaggedFAQCount = computed(() =>
|
||||
Math.max(overallFAQTotal.value - assignedFAQCount.value, 0),
|
||||
)
|
||||
const sidebarCategoryCount = computed(() => tagList.value.length)
|
||||
const filteredTags = computed(() => {
|
||||
const query = tagSearchQuery.value.trim().toLowerCase()
|
||||
if (!query) {
|
||||
|
||||
@@ -61,10 +61,14 @@ import (
|
||||
// Returns:
|
||||
// - Configured container with all application dependencies registered
|
||||
func BuildContainer(container *dig.Container) *dig.Container {
|
||||
ctx := context.Background()
|
||||
logger.Debugf(ctx, "[Container] Starting container initialization...")
|
||||
|
||||
// Register resource cleaner for proper cleanup of resources
|
||||
must(container.Provide(NewResourceCleaner, dig.As(new(interfaces.ResourceCleaner))))
|
||||
|
||||
// Core infrastructure configuration
|
||||
logger.Debugf(ctx, "[Container] Registering core infrastructure...")
|
||||
must(container.Provide(config.LoadConfig))
|
||||
must(container.Provide(initTracer))
|
||||
must(container.Provide(initDatabase))
|
||||
@@ -77,16 +81,21 @@ func BuildContainer(container *dig.Container) *dig.Container {
|
||||
must(container.Invoke(registerPoolCleanup))
|
||||
|
||||
// Initialize retrieval engine registry for search capabilities
|
||||
logger.Debugf(ctx, "[Container] Registering retrieval engine registry...")
|
||||
must(container.Provide(initRetrieveEngineRegistry))
|
||||
|
||||
// External service clients
|
||||
logger.Debugf(ctx, "[Container] Registering external service clients...")
|
||||
must(container.Provide(initDocReaderClient))
|
||||
must(container.Provide(initOllamaService))
|
||||
must(container.Provide(initNeo4jClient))
|
||||
must(container.Provide(stream.NewStreamManager))
|
||||
logger.Debugf(ctx, "[Container] Initializing DuckDB...")
|
||||
must(container.Provide(NewDuckDB))
|
||||
logger.Debugf(ctx, "[Container] DuckDB registered")
|
||||
|
||||
// Data repositories layer
|
||||
logger.Debugf(ctx, "[Container] Registering repositories...")
|
||||
must(container.Provide(repository.NewTenantRepository))
|
||||
must(container.Provide(repository.NewKnowledgeBaseRepository))
|
||||
must(container.Provide(repository.NewKnowledgeRepository))
|
||||
@@ -103,9 +112,11 @@ func BuildContainer(container *dig.Container) *dig.Container {
|
||||
must(container.Provide(service.NewWebSearchStateService))
|
||||
|
||||
// MCP manager for managing MCP client connections
|
||||
logger.Debugf(ctx, "[Container] Registering MCP manager...")
|
||||
must(container.Provide(mcp.NewMCPManager))
|
||||
|
||||
// Business service layer
|
||||
logger.Debugf(ctx, "[Container] Registering business services...")
|
||||
must(container.Provide(service.NewTenantService))
|
||||
must(container.Provide(service.NewKnowledgeBaseService))
|
||||
must(container.Provide(service.NewKnowledgeService))
|
||||
@@ -126,21 +137,26 @@ func BuildContainer(container *dig.Container) *dig.Container {
|
||||
must(container.Provide(service.NewCustomAgentService))
|
||||
|
||||
// Web search service (needed by AgentService)
|
||||
logger.Debugf(ctx, "[Container] Registering web search service...")
|
||||
must(container.Provide(service.NewWebSearchService))
|
||||
|
||||
// Agent service layer (requires event bus, web search service)
|
||||
// SessionService is passed as parameter to CreateAgentEngine method when creating AgentService
|
||||
logger.Debugf(ctx, "[Container] Registering event bus and agent service...")
|
||||
must(container.Provide(event.NewEventBus))
|
||||
must(container.Provide(service.NewAgentService))
|
||||
|
||||
// Session service (depends on agent service)
|
||||
// SessionService is created after AgentService and passes itself to AgentService.CreateAgentEngine when needed
|
||||
logger.Debugf(ctx, "[Container] Registering session service...")
|
||||
must(container.Provide(service.NewSessionService))
|
||||
|
||||
logger.Debugf(ctx, "[Container] Registering asynq client and server...")
|
||||
must(container.Provide(router.NewAsyncqClient))
|
||||
must(container.Provide(router.NewAsynqServer))
|
||||
|
||||
// Chat pipeline components for processing chat requests
|
||||
logger.Debugf(ctx, "[Container] Registering chat pipeline plugins...")
|
||||
must(container.Provide(chatpipline.NewEventManager))
|
||||
must(container.Invoke(chatpipline.NewPluginTracing))
|
||||
must(container.Invoke(chatpipline.NewPluginSearch))
|
||||
@@ -157,8 +173,10 @@ func BuildContainer(container *dig.Container) *dig.Container {
|
||||
must(container.Invoke(chatpipline.NewPluginExtractEntity))
|
||||
must(container.Invoke(chatpipline.NewPluginSearchEntity))
|
||||
must(container.Invoke(chatpipline.NewPluginSearchParallel))
|
||||
logger.Debugf(ctx, "[Container] Chat pipeline plugins registered")
|
||||
|
||||
// HTTP handlers layer
|
||||
logger.Debugf(ctx, "[Container] Registering HTTP handlers...")
|
||||
must(container.Provide(handler.NewTenantHandler))
|
||||
must(container.Provide(handler.NewKnowledgeBaseHandler))
|
||||
must(container.Provide(handler.NewKnowledgeHandler))
|
||||
@@ -175,11 +193,14 @@ func BuildContainer(container *dig.Container) *dig.Container {
|
||||
must(container.Provide(handler.NewMCPServiceHandler))
|
||||
must(container.Provide(handler.NewWebSearchHandler))
|
||||
must(container.Provide(handler.NewCustomAgentHandler))
|
||||
logger.Debugf(ctx, "[Container] HTTP handlers registered")
|
||||
|
||||
// Router configuration
|
||||
logger.Debugf(ctx, "[Container] Registering router and starting asynq server...")
|
||||
must(container.Provide(router.NewRouter))
|
||||
must(container.Invoke(router.RunAsynqServer))
|
||||
|
||||
logger.Infof(ctx, "[Container] Container initialization completed successfully")
|
||||
return container
|
||||
}
|
||||
|
||||
@@ -614,18 +635,32 @@ func NewDuckDB() (*sql.DB, error) {
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to open duckdb: %w", err)
|
||||
}
|
||||
ctx := context.Background()
|
||||
// Install and load the spatial extension which includes Excel support
|
||||
// Note: DuckDB doesn't have native Excel support, we need to use a workaround
|
||||
// Option 1: Install spatial extension (if available)
|
||||
|
||||
// Install and load the spatial extension with timeout to avoid blocking startup
|
||||
// The extension installation may download from network which can be slow or hang
|
||||
installTimeout := 30 * time.Second
|
||||
ctx, cancel := context.WithTimeout(context.Background(), installTimeout)
|
||||
defer cancel()
|
||||
|
||||
// Try to install spatial extension (may already be installed or network unavailable)
|
||||
installSQL := "INSTALL spatial;"
|
||||
if _, err := sqlDB.ExecContext(ctx, installSQL); err != nil {
|
||||
logger.Warnf(ctx, "[DuckDB] Failed to install spatial extension (may already be installed): %v", err)
|
||||
if ctx.Err() == context.DeadlineExceeded {
|
||||
logger.Warnf(context.Background(), "[DuckDB] Spatial extension installation timed out after %v, skipping", installTimeout)
|
||||
} else {
|
||||
logger.Warnf(context.Background(), "[DuckDB] Failed to install spatial extension (may already be installed): %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Try to load spatial extension
|
||||
loadSQL := "LOAD spatial;"
|
||||
if _, err := sqlDB.ExecContext(ctx, loadSQL); err != nil {
|
||||
logger.Warnf(ctx, "[DuckDB] Failed to load spatial extension: %v", err)
|
||||
if ctx.Err() == context.DeadlineExceeded {
|
||||
logger.Warnf(context.Background(), "[DuckDB] Spatial extension loading timed out, skipping")
|
||||
} else {
|
||||
logger.Warnf(context.Background(), "[DuckDB] Failed to load spatial extension: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
return sqlDB, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user