refactor(frontend): streamline knowledge base and agent handling with chat resources store

- Updated components to utilize the new `useChatResourcesStore` for managing knowledge bases and agents, improving data fetching and caching mechanisms.
- Refactored `AgentSelector`, `IMChannelPanel`, `Input-field`, and `menu` components to replace direct API calls with store methods, enhancing maintainability and performance.
- Adjusted knowledge base loading logic to ensure consistency across components and reduce redundant API requests.
- Improved session state handling in `settings` store to prevent overwriting user selections during state restoration.
This commit is contained in:
wizardchen
2026-06-08 20:55:54 +08:00
committed by lyingbug
parent dc8d4f686a
commit 815c72c964
22 changed files with 994 additions and 501 deletions
@@ -300,7 +300,7 @@ import { ref, watch, onMounted, computed } from 'vue'
import { MessagePlugin } from 'tdesign-vue-next'
import { useI18n } from 'vue-i18n'
import { extractTextRelations, fabriText, fabriTag, type Node, type Relation } from '@/api/initialization'
import { getSystemInfo } from '@/api/system'
import { useEditorResourcesStore } from '@/stores/editorResources'
import { useAuthStore } from '@/stores/auth'
const { t } = useI18n()
@@ -544,11 +544,13 @@ const clearExtractExample = () => {
MessagePlugin.success(t('graphSettings.exampleCleared'))
}
const editorResources = useEditorResourcesStore()
// 加载系统信息
const loadSystemInfo = async () => {
const loadSystemInfo = async (force = false) => {
try {
const response = await getSystemInfo()
systemInfo.value = response.data
await editorResources.ensureSystemInfo(force)
systemInfo.value = editorResources.systemInfo
} catch (error: any) {
console.error('Failed to load system info:', error)
}
@@ -86,11 +86,13 @@
<script setup lang="ts">
import { ref, watch, computed, onMounted, onUnmounted } from 'vue'
import { useI18n } from 'vue-i18n'
import { getParserEngines, type ParserEngineInfo } from '@/api/system'
import { type ParserEngineInfo } from '@/api/system'
import { useEditorResourcesStore } from '@/stores/editorResources'
import { useUIStore } from '@/stores/ui'
import { storeToRefs } from 'pinia'
const { t } = useI18n()
const editorResources = useEditorResourcesStore()
function getEngineDisplayName(engineName: string): string {
const key = `kbSettings.parser.engines.${engineName}.name`
@@ -253,13 +255,11 @@ function goToParserSettings() {
uiStore.openSettings('parser')
}
async function loadEngines() {
async function loadEngines(force = false) {
loading.value = true
try {
const resp = await getParserEngines()
if (resp?.data && Array.isArray(resp.data)) {
parserEngines.value = resp.data
}
await editorResources.ensureParserEngines(force)
parserEngines.value = editorResources.parserEngines as ParserEngineInfo[]
} catch {
parserEngines.value = []
} finally {
@@ -282,7 +282,7 @@ onMounted(loadEngines)
const { showSettingsModal } = storeToRefs(uiStore)
watch(showSettingsModal, (open, wasOpen) => {
if (wasOpen && !open) {
loadEngines()
loadEngines(true)
}
})
@@ -163,7 +163,7 @@
</template>
<script setup lang="ts">
import { ref, computed, watch, onMounted } from 'vue'
import { ref, computed, watch } from 'vue'
import { MessagePlugin } from 'tdesign-vue-next'
import { useI18n } from 'vue-i18n'
import { useOrganizationStore } from '@/stores/organization'
@@ -304,12 +304,6 @@ watch(() => props.kbId, async (newKbId) => {
await Promise.all([loadOrganizations(), loadShares()])
}
}, { immediate: true })
onMounted(async () => {
if (props.kbId) {
await Promise.all([loadOrganizations(), loadShares()])
}
})
</script>
<style scoped lang="less">
@@ -53,8 +53,9 @@
<script setup lang="ts">
import { ref, computed, watch, onMounted } from 'vue'
import { useI18n } from 'vue-i18n'
import { getStorageEngineConfig, getStorageEngineStatus, type StorageEngineStatusItem } from '@/api/system'
import { type StorageEngineStatusItem } from '@/api/system'
import { useUIStore } from '@/stores/ui'
import { useEditorResourcesStore } from '@/stores/editorResources'
const { t } = useI18n()
@@ -68,6 +69,7 @@ const emit = defineEmits<{
}>()
const uiStore = useUIStore()
const editorResources = useEditorResourcesStore()
// Keep empty until tenant default_provider is loaded — do not pre-fill 'local'.
const localProvider = ref(props.storageProvider)
const loading = ref(true)
@@ -176,18 +178,15 @@ function goToStorageSettings() {
uiStore.openSettings?.('storage')
}
async function load() {
async function load(force = false) {
loading.value = true
try {
const [configRes, statusRes] = await Promise.all([
getStorageEngineConfig(),
getStorageEngineStatus(),
])
const engines = statusRes?.data?.engines ?? []
await editorResources.ensureStorageEngine(force)
const engines = editorResources.storageStatus
engineStatus.value = engines
allowedProviders.value = statusRes?.data?.allowed_providers ?? []
defaultProvider.value = configRes?.data?.default_provider || 'local'
const d = configRes?.data
allowedProviders.value = editorResources.storageAllowedProviders
defaultProvider.value = editorResources.storageConfig?.default_provider || 'local'
const d = editorResources.storageConfig
hasAnyConfig.value = !!(d?.local?.path_prefix || d?.minio?.bucket_name || d?.cos?.bucket_name || d?.tos?.bucket_name || d?.s3?.bucket_name || d?.oss?.bucket_name || d?.ks3?.bucket_name || d?.obs?.bucket_name)
const parentUnset = !props.storageProvider
if (parentUnset) {