feat: introduce WeKnora Lite edition with lightweight configuration and deployment
- Added a new `.env.lite.example` file for the Lite version, providing a minimal configuration template. - Updated `.env.example` to remove deprecated variables and include new Docreader settings. - Enhanced Docker configurations to support the Lite version, including a new Dockerfile for the Docreader service. - Introduced a Makefile target for building and running the Lite version, along with packaging capabilities. - Created GitHub workflows for building and releasing Lite binaries, including Homebrew formula support. - Implemented a new service file for managing the Lite version as a system service. This update enables a streamlined, single-binary deployment of WeKnora, reducing external dependencies and simplifying setup.
This commit is contained in:
@@ -42,7 +42,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Multimodal feature -->
|
||||
<!-- Multimodal feature:仅选择多模态模型,存储引擎在「存储引擎」页配置 -->
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ $t('knowledgeEditor.advanced.multimodal.label') }}</label>
|
||||
@@ -57,9 +57,8 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Multimodal storage configuration -->
|
||||
<!-- 多模态开启时仅配置 VLLM 模型 -->
|
||||
<div v-if="localMultimodal.enabled" class="subsection">
|
||||
<!-- VLLM model -->
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ $t('knowledgeEditor.advanced.multimodal.vllmLabel') }} <span class="required">*</span></label>
|
||||
@@ -77,206 +76,6 @@
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="subsection-header">
|
||||
<h4>{{ $t('knowledgeEditor.advanced.multimodal.storageTitle') }} <span class="required">*</span></h4>
|
||||
</div>
|
||||
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ $t('knowledgeEditor.advanced.multimodal.storageTypeLabel') }} <span class="required">*</span></label>
|
||||
<p class="desc">{{ $t('knowledgeEditor.advanced.multimodal.storageTypeDescription') }}</p>
|
||||
<!-- Warning message when MinIO is not enabled -->
|
||||
<t-alert
|
||||
v-if="!isMinioEnabled"
|
||||
theme="warning"
|
||||
:message="$t('knowledgeEditor.advanced.multimodal.minioDisabledWarning')"
|
||||
style="margin-top: 8px;"
|
||||
/>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<t-radio-group v-model="localMultimodal.storageType" @change="handleStorageTypeChange">
|
||||
<t-radio value="minio" :disabled="!isMinioEnabled">
|
||||
{{ $t('knowledgeEditor.advanced.multimodal.storageTypeOptions.minio') }}
|
||||
</t-radio>
|
||||
<t-radio value="cos">{{ $t('knowledgeEditor.advanced.multimodal.storageTypeOptions.cos') }}</t-radio>
|
||||
</t-radio-group>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- MinIO configuration -->
|
||||
<div v-if="localMultimodal.storageType === 'minio'" class="storage-config">
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ $t('knowledgeEditor.advanced.multimodal.minio.bucketLabel') }} <span class="required">*</span></label>
|
||||
<p class="desc">{{ $t('knowledgeEditor.advanced.multimodal.minio.bucketDescription') }}</p>
|
||||
<p class="hint">{{ $t('knowledgeEditor.advanced.multimodal.minio.bucketHint') }}</p>
|
||||
</div>
|
||||
<div class="setting-control bucket-control">
|
||||
<t-select
|
||||
v-model="localMultimodal.minio.bucketName"
|
||||
:placeholder="$t('knowledgeEditor.advanced.multimodal.minio.bucketPlaceholder')"
|
||||
:loading="loadingBuckets"
|
||||
filterable
|
||||
creatable
|
||||
@change="handleConfigChange"
|
||||
@focus="loadMinioBuckets"
|
||||
style="width: 280px;"
|
||||
>
|
||||
<t-option
|
||||
v-for="bucket in minioBuckets"
|
||||
:key="bucket.name"
|
||||
:value="bucket.name"
|
||||
:label="bucket.name"
|
||||
>
|
||||
<div class="bucket-option">
|
||||
<span class="bucket-name">{{ bucket.name }}</span>
|
||||
<t-tag
|
||||
:theme="bucket.policy === 'public' ? 'success' : bucket.policy === 'private' ? 'default' : 'warning'"
|
||||
size="small"
|
||||
variant="light"
|
||||
>
|
||||
{{ $t(`knowledgeEditor.advanced.multimodal.minio.policyLabels.${bucket.policy}`) }}
|
||||
</t-tag>
|
||||
</div>
|
||||
</t-option>
|
||||
</t-select>
|
||||
<t-button
|
||||
theme="default"
|
||||
variant="outline"
|
||||
size="small"
|
||||
:loading="loadingBuckets"
|
||||
@click="loadMinioBuckets"
|
||||
style="margin-left: 8px;"
|
||||
>
|
||||
<template #icon><refresh-icon /></template>
|
||||
</t-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ $t('knowledgeEditor.advanced.multimodal.minio.useSslLabel') }}</label>
|
||||
<p class="desc">{{ $t('knowledgeEditor.advanced.multimodal.minio.useSslDescription') }}</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<t-switch
|
||||
v-model="localMultimodal.minio.useSSL"
|
||||
@change="handleConfigChange"
|
||||
size="large"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ $t('knowledgeEditor.advanced.multimodal.minio.pathPrefixLabel') }}</label>
|
||||
<p class="desc">{{ $t('knowledgeEditor.advanced.multimodal.minio.pathPrefixDescription') }}</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<t-input
|
||||
v-model="localMultimodal.minio.pathPrefix"
|
||||
:placeholder="$t('knowledgeEditor.advanced.multimodal.minio.pathPrefixPlaceholder')"
|
||||
@change="handleConfigChange"
|
||||
style="width: 280px;"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- COS configuration -->
|
||||
<div v-if="localMultimodal.storageType === 'cos'" class="storage-config">
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ $t('knowledgeEditor.advanced.multimodal.cos.secretIdLabel') }} <span class="required">*</span></label>
|
||||
<p class="desc">{{ $t('knowledgeEditor.advanced.multimodal.cos.secretIdDescription') }}</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<t-input
|
||||
v-model="localMultimodal.cos.secretId"
|
||||
:placeholder="$t('knowledgeEditor.advanced.multimodal.cos.secretIdPlaceholder')"
|
||||
@change="handleConfigChange"
|
||||
style="width: 280px;"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ $t('knowledgeEditor.advanced.multimodal.cos.secretKeyLabel') }} <span class="required">*</span></label>
|
||||
<p class="desc">{{ $t('knowledgeEditor.advanced.multimodal.cos.secretKeyDescription') }}</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<t-input
|
||||
v-model="localMultimodal.cos.secretKey"
|
||||
type="password"
|
||||
:placeholder="$t('knowledgeEditor.advanced.multimodal.cos.secretKeyPlaceholder')"
|
||||
@change="handleConfigChange"
|
||||
style="width: 280px;"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ $t('knowledgeEditor.advanced.multimodal.cos.regionLabel') }} <span class="required">*</span></label>
|
||||
<p class="desc">{{ $t('knowledgeEditor.advanced.multimodal.cos.regionDescription') }}</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<t-input
|
||||
v-model="localMultimodal.cos.region"
|
||||
:placeholder="$t('knowledgeEditor.advanced.multimodal.cos.regionPlaceholder')"
|
||||
@change="handleConfigChange"
|
||||
style="width: 280px;"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ $t('knowledgeEditor.advanced.multimodal.cos.bucketLabel') }} <span class="required">*</span></label>
|
||||
<p class="desc">{{ $t('knowledgeEditor.advanced.multimodal.cos.bucketDescription') }}</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<t-input
|
||||
v-model="localMultimodal.cos.bucketName"
|
||||
:placeholder="$t('knowledgeEditor.advanced.multimodal.cos.bucketPlaceholder')"
|
||||
@change="handleConfigChange"
|
||||
style="width: 280px;"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ $t('knowledgeEditor.advanced.multimodal.cos.appIdLabel') }} <span class="required">*</span></label>
|
||||
<p class="desc">{{ $t('knowledgeEditor.advanced.multimodal.cos.appIdDescription') }}</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<t-input
|
||||
v-model="localMultimodal.cos.appId"
|
||||
:placeholder="$t('knowledgeEditor.advanced.multimodal.cos.appIdPlaceholder')"
|
||||
@change="handleConfigChange"
|
||||
style="width: 280px;"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ $t('knowledgeEditor.advanced.multimodal.cos.pathPrefixLabel') }}</label>
|
||||
<p class="desc">{{ $t('knowledgeEditor.advanced.multimodal.cos.pathPrefixDescription') }}</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<t-input
|
||||
v-model="localMultimodal.cos.pathPrefix"
|
||||
:placeholder="$t('knowledgeEditor.advanced.multimodal.cos.pathPrefixPlaceholder')"
|
||||
@change="handleConfigChange"
|
||||
style="width: 280px;"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
@@ -284,31 +83,15 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, watch, onMounted } from 'vue'
|
||||
import { RefreshIcon } from 'tdesign-icons-vue-next'
|
||||
import { ref, watch } from 'vue'
|
||||
import ModelSelector from '@/components/ModelSelector.vue'
|
||||
import { useUIStore } from '@/stores/ui'
|
||||
import { getSystemInfo, listMinioBuckets, type MinioBucketInfo } from '@/api/system'
|
||||
|
||||
const uiStore = useUIStore()
|
||||
|
||||
interface MultimodalConfig {
|
||||
enabled: boolean
|
||||
storageType: 'minio' | 'cos'
|
||||
vllmModelId?: string
|
||||
minio: {
|
||||
bucketName: string
|
||||
useSSL: boolean
|
||||
pathPrefix: string
|
||||
}
|
||||
cos: {
|
||||
secretId: string
|
||||
secretKey: string
|
||||
region: string
|
||||
bucketName: string
|
||||
appId: string
|
||||
pathPrefix: string
|
||||
}
|
||||
}
|
||||
|
||||
interface QuestionGenerationConfig {
|
||||
@@ -335,58 +118,7 @@ const localQuestionGeneration = ref<QuestionGenerationConfig>(
|
||||
)
|
||||
|
||||
const vllmSelectorRef = ref()
|
||||
const isMinioEnabled = ref(false)
|
||||
const minioBuckets = ref<MinioBucketInfo[]>([])
|
||||
const loadingBuckets = ref(false)
|
||||
|
||||
// Load MinIO buckets
|
||||
const loadMinioBuckets = async () => {
|
||||
if (!isMinioEnabled.value || loadingBuckets.value) return
|
||||
|
||||
loadingBuckets.value = true
|
||||
try {
|
||||
const response = await listMinioBuckets()
|
||||
if (response.data?.buckets) {
|
||||
minioBuckets.value = response.data.buckets
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to load MinIO buckets:', error)
|
||||
} finally {
|
||||
loadingBuckets.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// Check system status on mount
|
||||
onMounted(async () => {
|
||||
try {
|
||||
const systemInfo = await getSystemInfo()
|
||||
|
||||
// Check MinIO status
|
||||
isMinioEnabled.value = systemInfo.data?.minio_enabled === true
|
||||
|
||||
// If MinIO is not enabled and storage type is minio, switch to cos
|
||||
if (!isMinioEnabled.value && localMultimodal.value.storageType === 'minio') {
|
||||
localMultimodal.value.storageType = 'cos'
|
||||
emit('update:multimodal', localMultimodal.value)
|
||||
}
|
||||
|
||||
// Load MinIO buckets if enabled
|
||||
if (isMinioEnabled.value) {
|
||||
loadMinioBuckets()
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch system info:', error)
|
||||
// Default to disabled if we can't fetch the info
|
||||
isMinioEnabled.value = false
|
||||
// If MinIO status unknown and storage type is minio, switch to cos
|
||||
if (localMultimodal.value.storageType === 'minio') {
|
||||
localMultimodal.value.storageType = 'cos'
|
||||
emit('update:multimodal', localMultimodal.value)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// Watch for prop changes
|
||||
watch(() => props.multimodal, (newVal) => {
|
||||
localMultimodal.value = { ...newVal }
|
||||
}, { deep: true })
|
||||
@@ -397,7 +129,6 @@ watch(() => props.questionGeneration, (newVal) => {
|
||||
}
|
||||
}, { deep: true })
|
||||
|
||||
// Handle question generation toggle
|
||||
const handleQuestionGenerationToggle = () => {
|
||||
if (!localQuestionGeneration.value.enabled) {
|
||||
localQuestionGeneration.value.questionCount = 3
|
||||
@@ -405,59 +136,25 @@ const handleQuestionGenerationToggle = () => {
|
||||
emit('update:questionGeneration', localQuestionGeneration.value)
|
||||
}
|
||||
|
||||
// Handle question generation config change
|
||||
const handleQuestionGenerationChange = () => {
|
||||
emit('update:questionGeneration', localQuestionGeneration.value)
|
||||
}
|
||||
|
||||
// Handle multimodal toggle
|
||||
const handleMultimodalToggle = () => {
|
||||
// Reset related configuration when multimodal is disabled
|
||||
if (!localMultimodal.value.enabled) {
|
||||
localMultimodal.value.vllmModelId = ''
|
||||
localMultimodal.value.minio = {
|
||||
bucketName: '',
|
||||
useSSL: false,
|
||||
pathPrefix: ''
|
||||
}
|
||||
localMultimodal.value.cos = {
|
||||
secretId: '',
|
||||
secretKey: '',
|
||||
region: '',
|
||||
bucketName: '',
|
||||
appId: '',
|
||||
pathPrefix: ''
|
||||
}
|
||||
}
|
||||
emit('update:multimodal', localMultimodal.value)
|
||||
}
|
||||
|
||||
// Handle storage type change
|
||||
const handleStorageTypeChange = () => {
|
||||
// Prevent switching to minio if it's not enabled
|
||||
if (localMultimodal.value.storageType === 'minio' && !isMinioEnabled.value) {
|
||||
localMultimodal.value.storageType = 'cos'
|
||||
}
|
||||
emit('update:multimodal', localMultimodal.value)
|
||||
}
|
||||
|
||||
// Handle VLLM model change
|
||||
const handleVLLMChange = (modelId: string) => {
|
||||
localMultimodal.value.vllmModelId = modelId
|
||||
emit('update:multimodal', localMultimodal.value)
|
||||
}
|
||||
|
||||
// Navigate to model management when adding models
|
||||
const handleAddModel = (subSection: string) => {
|
||||
uiStore.openSettings('models', subSection)
|
||||
}
|
||||
|
||||
// Handle configuration change
|
||||
const handleConfigChange = () => {
|
||||
emit('update:multimodal', localMultimodal.value)
|
||||
}
|
||||
|
||||
// The allModels prop keeps model options in sync
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
@@ -546,104 +243,11 @@ const handleConfigChange = () => {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.subsection-header {
|
||||
margin: 16px 0 8px 0;
|
||||
|
||||
&:first-child {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
h4 {
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
color: #333333;
|
||||
margin: 0;
|
||||
padding-left: 8px;
|
||||
border-left: 2px solid #07C05F;
|
||||
|
||||
.required {
|
||||
color: #e34d59;
|
||||
margin-left: 4px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.required {
|
||||
color: #e34d59;
|
||||
margin-left: 2px;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.storage-config {
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.bucket-control {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.bucket-option {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
width: 100%;
|
||||
|
||||
.bucket-name {
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
}
|
||||
|
||||
.config-item {
|
||||
background: #ffffff;
|
||||
border: 1px solid #e5e7eb;
|
||||
border-radius: 6px;
|
||||
padding: 16px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.config-item-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 16px;
|
||||
padding-bottom: 12px;
|
||||
border-bottom: 1px solid #f0f0f0;
|
||||
}
|
||||
|
||||
.config-item-title {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: #333333;
|
||||
}
|
||||
|
||||
.config-item-body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.config-field {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
|
||||
label {
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
color: #555555;
|
||||
}
|
||||
}
|
||||
|
||||
.subsection-desc {
|
||||
font-size: 13px;
|
||||
color: #666666;
|
||||
margin: 4px 0 8px 8px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
|
||||
@@ -77,10 +77,16 @@
|
||||
import { ref, watch, computed } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
interface ParserEngineRule {
|
||||
file_types: string[]
|
||||
engine: string
|
||||
}
|
||||
|
||||
interface ChunkingConfig {
|
||||
chunkSize: number
|
||||
chunkOverlap: number
|
||||
separators: string[]
|
||||
parserEngineRules?: ParserEngineRule[]
|
||||
}
|
||||
|
||||
interface Props {
|
||||
@@ -98,7 +104,6 @@ const localChunkOverlap = ref(props.config.chunkOverlap)
|
||||
const localSeparators = ref([...props.config.separators])
|
||||
const { t } = useI18n()
|
||||
|
||||
// Separator options
|
||||
const separatorOptions = computed(() => [
|
||||
{ label: t('knowledgeEditor.chunking.separators.doubleNewline'), value: '\n\n' },
|
||||
{ label: t('knowledgeEditor.chunking.separators.singleNewline'), value: '\n' },
|
||||
@@ -110,34 +115,22 @@ const separatorOptions = computed(() => [
|
||||
{ label: t('knowledgeEditor.chunking.separators.space'), value: ' ' }
|
||||
])
|
||||
|
||||
// Watch for prop changes
|
||||
watch(() => props.config, (newConfig) => {
|
||||
localChunkSize.value = newConfig.chunkSize
|
||||
localChunkOverlap.value = newConfig.chunkOverlap
|
||||
localSeparators.value = [...newConfig.separators]
|
||||
}, { deep: true })
|
||||
|
||||
// Handle chunk size change
|
||||
const handleChunkSizeChange = () => {
|
||||
emitUpdate()
|
||||
}
|
||||
const handleChunkSizeChange = () => { emitUpdate() }
|
||||
const handleChunkOverlapChange = () => { emitUpdate() }
|
||||
const handleSeparatorsChange = () => { emitUpdate() }
|
||||
|
||||
// Handle chunk overlap change
|
||||
const handleChunkOverlapChange = () => {
|
||||
emitUpdate()
|
||||
}
|
||||
|
||||
// Handle separator change
|
||||
const handleSeparatorsChange = () => {
|
||||
emitUpdate()
|
||||
}
|
||||
|
||||
// Emit update event
|
||||
const emitUpdate = () => {
|
||||
emit('update:config', {
|
||||
chunkSize: localChunkSize.value,
|
||||
chunkOverlap: localChunkOverlap.value,
|
||||
separators: localSeparators.value
|
||||
separators: localSeparators.value,
|
||||
parserEngineRules: props.config.parserEngineRules
|
||||
})
|
||||
}
|
||||
</script>
|
||||
@@ -228,4 +221,3 @@ const emitUpdate = () => {
|
||||
text-align: right;
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
@@ -0,0 +1,456 @@
|
||||
<template>
|
||||
<div class="kb-parser-settings">
|
||||
<div class="section-header">
|
||||
<h2>解析引擎</h2>
|
||||
<p class="section-description">为不同文件类型选择文档解析引擎。未配置的文件类型将使用内置解析引擎。</p>
|
||||
</div>
|
||||
|
||||
<div v-if="loading" class="loading-inline">
|
||||
<t-loading size="small" />
|
||||
<span>加载中...</span>
|
||||
</div>
|
||||
|
||||
<div v-else-if="fileTypeGroups.length === 0" class="empty-hint">
|
||||
<p>暂无可用解析引擎,或文档解析服务未配置。</p>
|
||||
</div>
|
||||
|
||||
<div v-else class="settings-group">
|
||||
<div
|
||||
v-for="group in fileTypeGroups"
|
||||
:key="group.key"
|
||||
class="setting-row"
|
||||
>
|
||||
<div class="setting-info">
|
||||
<label class="group-label">
|
||||
<t-icon :name="group.icon" class="group-icon" />
|
||||
{{ group.label }}
|
||||
</label>
|
||||
<div class="ext-tags">
|
||||
<span v-for="ext in group.extensions" :key="ext" class="ext-tag">.{{ ext }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<t-select
|
||||
:value="getEngineForGroup(group.extensions) || undefined"
|
||||
@change="(val: string) => handleEngineChange(group.extensions, val)"
|
||||
style="width: 280px;"
|
||||
:status="hasAvailableEngine(group.extensions) ? 'default' : 'warning'"
|
||||
placeholder="无可用引擎"
|
||||
>
|
||||
<t-option
|
||||
v-for="opt in getEngineOptions(group.extensions)"
|
||||
:key="opt.value"
|
||||
:value="opt.value"
|
||||
:label="opt.selectLabel"
|
||||
:disabled="opt.disabled"
|
||||
>
|
||||
<t-tooltip
|
||||
:content="`支持格式: ${opt.fileTypes.map(t => '.' + t).join(' ')}`"
|
||||
placement="left"
|
||||
:show-arrow="false"
|
||||
>
|
||||
<div class="engine-option">
|
||||
<div class="engine-option-top">
|
||||
<span class="engine-option-name">{{ opt.value }}</span>
|
||||
<t-tag
|
||||
v-if="opt.isDefault"
|
||||
theme="primary"
|
||||
variant="light"
|
||||
size="small"
|
||||
>默认</t-tag>
|
||||
<t-tag
|
||||
v-if="opt.disabled"
|
||||
theme="danger"
|
||||
variant="light"
|
||||
size="small"
|
||||
>不可用</t-tag>
|
||||
</div>
|
||||
<div class="engine-option-desc">{{ opt.desc }}</div>
|
||||
<div v-if="opt.disabled && opt.reason" class="engine-option-reason">
|
||||
{{ opt.reason }}
|
||||
<a class="go-settings" @click.stop.prevent="goToParserSettings">去设置 →</a>
|
||||
</div>
|
||||
</div>
|
||||
</t-tooltip>
|
||||
</t-option>
|
||||
</t-select>
|
||||
<div v-if="!hasAvailableEngine(group.extensions)" class="no-engine-warning">
|
||||
<a class="go-settings" @click.prevent="goToParserSettings">前往配置 →</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, watch, computed, onMounted, onUnmounted } from 'vue'
|
||||
import { getParserEngines, type ParserEngineInfo } from '@/api/system'
|
||||
import { useUIStore } from '@/stores/ui'
|
||||
import { storeToRefs } from 'pinia'
|
||||
|
||||
export interface ParserEngineRule {
|
||||
file_types: string[]
|
||||
engine: string
|
||||
}
|
||||
|
||||
interface EngineOption {
|
||||
value: string
|
||||
selectLabel: string
|
||||
desc: string
|
||||
fileTypes: string[]
|
||||
disabled: boolean
|
||||
isDefault: boolean
|
||||
reason?: string
|
||||
}
|
||||
|
||||
interface Props {
|
||||
parserEngineRules?: ParserEngineRule[]
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
parserEngineRules: () => []
|
||||
})
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:parserEngineRules': [value: ParserEngineRule[]]
|
||||
}>()
|
||||
|
||||
const uiStore = useUIStore()
|
||||
const localEngineRules = ref<ParserEngineRule[]>([...props.parserEngineRules])
|
||||
const parserEngines = ref<ParserEngineInfo[]>([])
|
||||
const loading = ref(true)
|
||||
|
||||
const allFileTypes = computed(() => {
|
||||
const s = new Set<string>()
|
||||
for (const engine of parserEngines.value) {
|
||||
for (const ft of engine.FileTypes || []) {
|
||||
s.add(ft)
|
||||
}
|
||||
}
|
||||
return s
|
||||
})
|
||||
|
||||
const fileTypeGroups = computed(() => {
|
||||
const ft = allFileTypes.value
|
||||
const groups: { key: string; label: string; icon: string; extensions: string[] }[] = []
|
||||
|
||||
const pdfExts = ['pdf'].filter(e => ft.has(e))
|
||||
const officeExts = ['docx', 'doc'].filter(e => ft.has(e))
|
||||
const pptExts = ['pptx', 'ppt'].filter(e => ft.has(e))
|
||||
const excelExts = ['xlsx', 'xls'].filter(e => ft.has(e))
|
||||
const csvExts = ['csv'].filter(e => ft.has(e))
|
||||
const mdExts = ['md', 'markdown'].filter(e => ft.has(e))
|
||||
const txtExts = ['txt'].filter(e => ft.has(e))
|
||||
const imageExts = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'tiff', 'webp'].filter(e => ft.has(e))
|
||||
|
||||
if (pdfExts.length) groups.push({ key: 'pdf', label: 'PDF 文档', icon: 'file-pdf', extensions: pdfExts })
|
||||
if (officeExts.length) groups.push({ key: 'office', label: 'Word 文档', icon: 'file-word', extensions: officeExts })
|
||||
if (pptExts.length) groups.push({ key: 'ppt', label: '演示文稿', icon: 'file-powerpoint', extensions: pptExts })
|
||||
if (excelExts.length) groups.push({ key: 'excel', label: 'Excel 表格', icon: 'file-excel', extensions: excelExts })
|
||||
if (csvExts.length) groups.push({ key: 'csv', label: 'CSV 文件', icon: 'file-excel', extensions: csvExts })
|
||||
if (mdExts.length) groups.push({ key: 'markdown', label: 'Markdown', icon: 'file-code', extensions: mdExts })
|
||||
if (txtExts.length) groups.push({ key: 'text', label: '纯文本', icon: 'file', extensions: txtExts })
|
||||
if (imageExts.length) groups.push({ key: 'image', label: '图片', icon: 'image', extensions: imageExts })
|
||||
|
||||
return groups
|
||||
})
|
||||
|
||||
function getEngineOptions(extensions: string[]): EngineOption[] {
|
||||
const raw: { name: string; desc: string; fileTypes: string[]; available: boolean; reason: string }[] = []
|
||||
for (const engine of parserEngines.value) {
|
||||
const supports = extensions.some(ext => (engine.FileTypes || []).includes(ext))
|
||||
if (supports) {
|
||||
raw.push({
|
||||
name: engine.Name,
|
||||
desc: engine.Description || engine.Name,
|
||||
fileTypes: engine.FileTypes || [],
|
||||
available: engine.Available !== false,
|
||||
reason: engine.UnavailableReason || '',
|
||||
})
|
||||
}
|
||||
}
|
||||
const defaultName = raw.find(e => e.available)?.name ?? ''
|
||||
return raw.map(e => ({
|
||||
value: e.name,
|
||||
selectLabel: `${e.name} — ${e.desc}`,
|
||||
desc: e.desc,
|
||||
fileTypes: e.fileTypes,
|
||||
disabled: !e.available,
|
||||
isDefault: defaultName !== '' && e.name === defaultName,
|
||||
reason: e.reason,
|
||||
}))
|
||||
}
|
||||
|
||||
function hasAvailableEngine(extensions: string[]): boolean {
|
||||
return getEngineOptions(extensions).some(opt => !opt.disabled)
|
||||
}
|
||||
|
||||
function getDefaultEngine(extensions: string[]): string {
|
||||
const opts = getEngineOptions(extensions)
|
||||
return opts.find(o => o.isDefault)?.value ?? ''
|
||||
}
|
||||
|
||||
function getEngineForGroup(extensions: string[]): string {
|
||||
for (const rule of localEngineRules.value) {
|
||||
if (rule.file_types.some(ft => extensions.includes(ft))) {
|
||||
return rule.engine
|
||||
}
|
||||
}
|
||||
return getDefaultEngine(extensions)
|
||||
}
|
||||
|
||||
function handleEngineChange(extensions: string[], engine: string) {
|
||||
const otherRules = localEngineRules.value.filter(
|
||||
r => !r.file_types.some(ft => extensions.includes(ft))
|
||||
)
|
||||
if (engine) {
|
||||
otherRules.push({ file_types: [...extensions], engine })
|
||||
}
|
||||
localEngineRules.value = otherRules
|
||||
emit('update:parserEngineRules', buildCompleteRules())
|
||||
}
|
||||
|
||||
function buildCompleteRules(): ParserEngineRule[] {
|
||||
const rules: ParserEngineRule[] = []
|
||||
for (const group of fileTypeGroups.value) {
|
||||
const engine = getEngineForGroup(group.extensions)
|
||||
if (engine) {
|
||||
rules.push({ file_types: [...group.extensions], engine })
|
||||
}
|
||||
}
|
||||
return rules
|
||||
}
|
||||
|
||||
function goToParserSettings() {
|
||||
uiStore.openSettings('parser')
|
||||
}
|
||||
|
||||
async function loadEngines() {
|
||||
loading.value = true
|
||||
try {
|
||||
const resp = await getParserEngines()
|
||||
if (resp?.data && Array.isArray(resp.data)) {
|
||||
parserEngines.value = resp.data
|
||||
}
|
||||
} catch {
|
||||
parserEngines.value = []
|
||||
} finally {
|
||||
loading.value = false
|
||||
ensureCompleteRules()
|
||||
}
|
||||
}
|
||||
|
||||
function ensureCompleteRules() {
|
||||
if (!parserEngines.value.length) return
|
||||
const complete = buildCompleteRules()
|
||||
if (complete.length && complete.length > localEngineRules.value.length) {
|
||||
localEngineRules.value = complete
|
||||
emit('update:parserEngineRules', complete)
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(loadEngines)
|
||||
|
||||
const { showSettingsModal } = storeToRefs(uiStore)
|
||||
watch(showSettingsModal, (open, wasOpen) => {
|
||||
if (wasOpen && !open) {
|
||||
loadEngines()
|
||||
}
|
||||
})
|
||||
|
||||
watch(() => props.parserEngineRules, (v) => {
|
||||
localEngineRules.value = v?.length ? [...v] : []
|
||||
}, { deep: true })
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.kb-parser-settings {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.section-header {
|
||||
margin-bottom: 32px;
|
||||
|
||||
h2 {
|
||||
font-size: 20px;
|
||||
font-weight: 600;
|
||||
color: #333;
|
||||
margin: 0 0 8px 0;
|
||||
}
|
||||
|
||||
.section-description {
|
||||
font-size: 14px;
|
||||
color: #666;
|
||||
margin: 0;
|
||||
line-height: 1.5;
|
||||
}
|
||||
}
|
||||
|
||||
.loading-inline {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 16px 0;
|
||||
}
|
||||
|
||||
.empty-hint {
|
||||
padding: 24px 0;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.settings-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0;
|
||||
}
|
||||
|
||||
.setting-row {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
padding: 20px 0;
|
||||
border-bottom: 1px solid #e5e7eb;
|
||||
|
||||
&:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
}
|
||||
|
||||
.setting-info {
|
||||
flex: 1;
|
||||
max-width: 65%;
|
||||
padding-right: 24px;
|
||||
|
||||
.group-label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.group-icon {
|
||||
font-size: 18px;
|
||||
color: #555;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
label {
|
||||
font-size: 15px;
|
||||
font-weight: 500;
|
||||
color: #333;
|
||||
display: block;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.ext-tags {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 6px;
|
||||
margin-top: 6px;
|
||||
}
|
||||
|
||||
.ext-tag {
|
||||
display: inline-block;
|
||||
font-size: 12px;
|
||||
line-height: 1;
|
||||
color: #555;
|
||||
background: #f3f4f6;
|
||||
padding: 3px 8px;
|
||||
border-radius: 4px;
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
|
||||
}
|
||||
|
||||
.desc {
|
||||
font-size: 13px;
|
||||
color: #666;
|
||||
margin: 0;
|
||||
line-height: 1.5;
|
||||
}
|
||||
}
|
||||
|
||||
.setting-control {
|
||||
flex-shrink: 0;
|
||||
min-width: 280px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-end;
|
||||
}
|
||||
|
||||
.no-engine-warning {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
margin-top: 8px;
|
||||
font-size: 12px;
|
||||
color: #e37318;
|
||||
line-height: 1.4;
|
||||
|
||||
.go-settings {
|
||||
color: #07C05F;
|
||||
cursor: pointer;
|
||||
white-space: nowrap;
|
||||
text-decoration: none;
|
||||
|
||||
&:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---- 下拉选项样式 ----
|
||||
.engine-option {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 3px;
|
||||
padding: 3px 0;
|
||||
}
|
||||
|
||||
.engine-option-top {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.engine-option-name {
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
color: #333;
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
|
||||
}
|
||||
|
||||
.engine-option-desc {
|
||||
font-size: 12px;
|
||||
color: #888;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.engine-option-reason {
|
||||
font-size: 12px;
|
||||
color: #e34d59;
|
||||
line-height: 1.4;
|
||||
|
||||
.go-settings {
|
||||
color: #07C05F;
|
||||
cursor: pointer;
|
||||
margin-left: 4px;
|
||||
font-size: 12px;
|
||||
text-decoration: none;
|
||||
|
||||
&:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
<style lang="less">
|
||||
.t-select__dropdown .t-select-option {
|
||||
height: auto;
|
||||
align-items: flex-start;
|
||||
padding-top: 6px;
|
||||
padding-bottom: 6px;
|
||||
}
|
||||
.t-select__dropdown .t-select-option__content {
|
||||
white-space: normal;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,244 @@
|
||||
<template>
|
||||
<div class="kb-storage-settings">
|
||||
<div class="section-header">
|
||||
<h2>存储引擎</h2>
|
||||
<p class="section-description">
|
||||
选择文件存储引擎,影响文档上传存储和文档中图片的存储方式。参数在全局设置中配置。
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div v-if="loading" class="loading-inline">
|
||||
<t-loading size="small" />
|
||||
<span>加载中...</span>
|
||||
</div>
|
||||
|
||||
<div v-else class="settings-group">
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>存储引擎</label>
|
||||
<p class="desc">选择该知识库使用的存储引擎,需在全局设置中已配置对应引擎。</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<t-select
|
||||
v-model="localProvider"
|
||||
size="medium"
|
||||
placeholder="请选择存储引擎"
|
||||
style="width: 100%; min-width: 220px;"
|
||||
@change="handleChange"
|
||||
>
|
||||
<t-option
|
||||
v-for="opt in engineOptions"
|
||||
:key="opt.value"
|
||||
:value="opt.value"
|
||||
:label="opt.label"
|
||||
:disabled="opt.disabled"
|
||||
>
|
||||
<span class="select-option">
|
||||
<span>{{ opt.label }}</span>
|
||||
<t-tag v-if="opt.disabled" theme="warning" variant="light" size="small">未配置</t-tag>
|
||||
<t-tag v-else-if="opt.available === false" theme="danger" variant="light" size="small">不可用</t-tag>
|
||||
</span>
|
||||
</t-option>
|
||||
</t-select>
|
||||
<p v-if="selectedOption?.desc" class="option-hint">{{ selectedOption.desc }}</p>
|
||||
<a v-if="showGoSettings" href="javascript:void(0)" class="go-settings" @click.prevent="goToStorageSettings">去全局设置中配置</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, watch, onMounted } from 'vue'
|
||||
import { getStorageEngineConfig, getStorageEngineStatus, type StorageEngineStatusItem } from '@/api/system'
|
||||
import { useUIStore } from '@/stores/ui'
|
||||
|
||||
const props = defineProps<{
|
||||
storageProvider: string
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:storageProvider': [value: string]
|
||||
}>()
|
||||
|
||||
const uiStore = useUIStore()
|
||||
const localProvider = ref(props.storageProvider || 'local')
|
||||
const loading = ref(true)
|
||||
const engineStatus = ref<StorageEngineStatusItem[]>([])
|
||||
const defaultProvider = ref('local')
|
||||
const hasAnyConfig = ref(false)
|
||||
|
||||
const engineOptions = computed(() => {
|
||||
const statusMap: Record<string, boolean> = {}
|
||||
for (const e of engineStatus.value) {
|
||||
statusMap[e.name] = e.available
|
||||
}
|
||||
return [
|
||||
{
|
||||
value: 'local',
|
||||
label: 'Local(本地存储)',
|
||||
desc: '仅适合单机部署,简单轻量',
|
||||
available: statusMap.local !== false,
|
||||
disabled: false,
|
||||
},
|
||||
{
|
||||
value: 'minio',
|
||||
label: 'MinIO',
|
||||
desc: 'S3 兼容,适合内网或私有云',
|
||||
available: statusMap.minio,
|
||||
disabled: statusMap.minio === false,
|
||||
},
|
||||
{
|
||||
value: 'cos',
|
||||
label: '腾讯云 COS',
|
||||
desc: '公有云部署,支持 CDN 加速',
|
||||
available: statusMap.cos,
|
||||
disabled: statusMap.cos === false,
|
||||
},
|
||||
]
|
||||
})
|
||||
|
||||
const showGoSettings = computed(() =>
|
||||
engineOptions.value.some(o => o.disabled)
|
||||
)
|
||||
|
||||
const selectedOption = computed(() =>
|
||||
engineOptions.value.find(o => o.value === localProvider.value)
|
||||
)
|
||||
|
||||
function handleChange() {
|
||||
emit('update:storageProvider', localProvider.value)
|
||||
}
|
||||
|
||||
function goToStorageSettings() {
|
||||
uiStore.closeKBEditor?.()
|
||||
uiStore.openSettings?.('storage')
|
||||
}
|
||||
|
||||
async function load() {
|
||||
loading.value = true
|
||||
try {
|
||||
const [configRes, statusRes] = await Promise.all([
|
||||
getStorageEngineConfig(),
|
||||
getStorageEngineStatus(),
|
||||
])
|
||||
const engines = statusRes?.data?.engines ?? []
|
||||
engineStatus.value = engines
|
||||
defaultProvider.value = configRes?.data?.default_provider || 'local'
|
||||
const d = configRes?.data
|
||||
hasAnyConfig.value = !!(d?.local?.path_prefix || d?.minio?.bucket_name || d?.cos?.bucket_name)
|
||||
if (!localProvider.value || localProvider.value === '') {
|
||||
localProvider.value = defaultProvider.value
|
||||
emit('update:storageProvider', localProvider.value)
|
||||
}
|
||||
} catch {
|
||||
engineStatus.value = []
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
watch(() => props.storageProvider, (v) => {
|
||||
localProvider.value = v || defaultProvider.value || 'local'
|
||||
}, { immediate: true })
|
||||
|
||||
onMounted(load)
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.kb-storage-settings {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.section-header {
|
||||
margin-bottom: 32px;
|
||||
|
||||
h2 {
|
||||
font-size: 20px;
|
||||
font-weight: 600;
|
||||
color: #333;
|
||||
margin: 0 0 8px 0;
|
||||
}
|
||||
|
||||
.section-description {
|
||||
font-size: 14px;
|
||||
color: #666;
|
||||
margin: 0;
|
||||
line-height: 1.5;
|
||||
}
|
||||
}
|
||||
|
||||
.loading-inline {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 16px 0;
|
||||
}
|
||||
|
||||
.settings-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.setting-row {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
padding: 20px 0;
|
||||
border-bottom: 1px solid #e5e7eb;
|
||||
}
|
||||
|
||||
.setting-info {
|
||||
flex: 1;
|
||||
max-width: 65%;
|
||||
padding-right: 24px;
|
||||
|
||||
label {
|
||||
font-size: 15px;
|
||||
font-weight: 500;
|
||||
color: #333;
|
||||
display: block;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.desc {
|
||||
font-size: 13px;
|
||||
color: #666;
|
||||
margin: 0;
|
||||
line-height: 1.5;
|
||||
}
|
||||
}
|
||||
|
||||
.setting-control {
|
||||
flex-shrink: 0;
|
||||
min-width: 280px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.select-option {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.option-hint {
|
||||
font-size: 12px;
|
||||
color: #999;
|
||||
margin: 0;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.go-settings {
|
||||
font-size: 13px;
|
||||
color: var(--td-brand-color, #0052d9);
|
||||
margin-top: 8px;
|
||||
text-decoration: none;
|
||||
|
||||
&:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user