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