diff --git a/frontend/src/i18n/locales/en-US.ts b/frontend/src/i18n/locales/en-US.ts index 77f824a9..3253440e 100755 --- a/frontend/src/i18n/locales/en-US.ts +++ b/frontend/src/i18n/locales/en-US.ts @@ -867,6 +867,15 @@ export default { editor: { createTitle: 'Create Agent', editTitle: 'Edit Agent', + buttons: { + create: 'Create Agent', + saveAndClose: 'Save and Close', + }, + postCreateHint: { + title: 'Created successfully', + footer: 'Keep adjusting settings, configure sharing and publishing, then click "Save and Close".', + integrationDesc: 'Go to Integrations to configure IM, web embed, and other publishing channels', + }, basicInfo: 'Basic Info', basicInfoDesc: 'Configure agent name, description, and run mode', promptsConfig: 'Prompts', @@ -2229,7 +2238,13 @@ export default { }, buttons: { create: 'Create Knowledge Base', - save: 'Save Configuration' + save: 'Save Configuration', + saveAndClose: 'Save and Close', + }, + postCreateHint: { + title: 'Created successfully', + footer: 'Keep adjusting settings, configure sharing and data sources, then click "Save and Close".', + followUpDesc: 'Configure data sources on the left, or use Share Management to publish to spaces', }, share: { description: 'Share the knowledge base with spaces so members can access and use it', diff --git a/frontend/src/i18n/locales/ko-KR.ts b/frontend/src/i18n/locales/ko-KR.ts index a78b2611..5c212c61 100755 --- a/frontend/src/i18n/locales/ko-KR.ts +++ b/frontend/src/i18n/locales/ko-KR.ts @@ -3455,7 +3455,13 @@ export default { }, buttons: { create: '지식베이스 생성', - save: '설정 저장' + save: '설정 저장', + saveAndClose: '저장 후 닫기', + }, + postCreateHint: { + title: '생성 완료', + footer: '설정을 계속 조정하고 공유·데이터 소스를 구성한 뒤 "저장 후 닫기"를 클릭하세요.', + followUpDesc: '왼쪽에서 데이터 소스를 구성하거나 "공유 관리"에서 스페이스에 게시할 수 있습니다', }, wikiBrowser: { editBtn: '편집', @@ -4760,6 +4766,15 @@ export default { editor: { createTitle: '에이전트 만들기', editTitle: '에이전트 편집', + buttons: { + create: '에이전트 만들기', + saveAndClose: '저장 후 닫기', + }, + postCreateHint: { + title: '생성 완료', + footer: '설정을 계속 조정하고 공유·배포 채널을 구성한 뒤 "저장 후 닫기"를 클릭하세요.', + integrationDesc: '통합 센터에서 IM, 웹 임베드 등 배포 채널을 설정하세요', + }, basicInfo: '기본정보', basicInfoDesc: '에이전트 이름, 설명 및 실행 모드 구성', promptsConfig: '프롬프트', diff --git a/frontend/src/i18n/locales/ru-RU.ts b/frontend/src/i18n/locales/ru-RU.ts index 424de631..b5655768 100755 --- a/frontend/src/i18n/locales/ru-RU.ts +++ b/frontend/src/i18n/locales/ru-RU.ts @@ -3455,7 +3455,13 @@ export default { }, buttons: { create: 'Создать базу знаний', - save: 'Сохранить настройки' + save: 'Сохранить настройки', + saveAndClose: 'Сохранить и закрыть', + }, + postCreateHint: { + title: 'База знаний создана', + footer: 'Продолжите настройку, настройте совместное использование и источники данных, затем нажмите «Сохранить и закрыть».', + followUpDesc: 'Настройте источники данных слева или опубликуйте базу в пространствах через «Управление общим доступом»', }, wikiBrowser: { editBtn: 'Редактировать', @@ -4760,6 +4766,15 @@ export default { editor: { createTitle: 'Create Agent', editTitle: 'Edit Agent', + buttons: { + create: 'Создать агента', + saveAndClose: 'Сохранить и закрыть', + }, + postCreateHint: { + title: 'Агент создан', + footer: 'Продолжите настройку, настройте совместное использование и публикацию, затем нажмите «Сохранить и закрыть».', + integrationDesc: 'Перейдите в раздел интеграций, чтобы настроить каналы IM, веб-встраивания и другие каналы публикации', + }, basicInfo: 'Basic Info', basicInfoDesc: 'Настройка имени, описания и режима работы агента', promptsConfig: 'Промпты', diff --git a/frontend/src/i18n/locales/zh-CN.ts b/frontend/src/i18n/locales/zh-CN.ts index a7c5618e..e1948910 100755 --- a/frontend/src/i18n/locales/zh-CN.ts +++ b/frontend/src/i18n/locales/zh-CN.ts @@ -3455,7 +3455,13 @@ export default { }, buttons: { create: '创建知识库', - save: '保存配置' + save: '保存配置', + saveAndClose: '保存并关闭', + }, + postCreateHint: { + title: '创建成功', + footer: '可继续调整配置,设置共享与数据源,完成后点击「保存并关闭」。', + followUpDesc: '可在左侧配置数据源,或在「共享管理」中发布到空间', }, wikiBrowser: { editBtn: '编辑', @@ -4760,6 +4766,15 @@ export default { editor: { createTitle: '创建智能体', editTitle: '编辑智能体', + buttons: { + create: '创建智能体', + saveAndClose: '保存并关闭', + }, + postCreateHint: { + title: '创建成功', + footer: '可继续调整配置,设置共享与发布渠道,完成后点击「保存并关闭」。', + integrationDesc: '前往集成中心配置 IM、网页嵌入等发布渠道', + }, basicInfo: '基本信息', basicInfoDesc: '配置智能体的名称、描述与运行模式', promptsConfig: '提示词', diff --git a/frontend/src/views/agent/AgentEditorModal.test.mjs b/frontend/src/views/agent/AgentEditorModal.test.mjs new file mode 100644 index 00000000..834c402d --- /dev/null +++ b/frontend/src/views/agent/AgentEditorModal.test.mjs @@ -0,0 +1,36 @@ +import assert from 'node:assert/strict' +import { readFileSync } from 'node:fs' +import test from 'node:test' + +const source = readFileSync(new URL('./AgentEditorModal.vue', import.meta.url), 'utf8') + +test('editing an agent closes the editor after a successful save', () => { + assert.match( + source, + /await updateAgent\(formData\.value\.id, formData\.value\);\s*MessagePlugin\.success\(t\('agent\.messages\.updated'\)\);\s*emit\('success'\);\s*handleClose\(\);/ + ) +}) + +test('the first successful create stays open for integration setup', () => { + const createBranch = source.match( + /if \(editorMode\.value === 'create'\) \{([\s\S]*?)^\s{4}\} else \{/m + )?.[1] + + assert.ok(createBranch, 'expected to find the create branch') + assert.doesNotMatch(createBranch, /handleClose\(\)/) + assert.match(createBranch, /savedAgent\.value = created;/) +}) + +test('save button labels distinguish create from save-and-close', () => { + assert.match( + source, + /const saveButtonLabel = computed\(\(\) =>\s*editorMode\.value === 'create'\s*\? t\('agent\.editor\.buttons\.create'\)\s*: t\('agent\.editor\.buttons\.saveAndClose'\)\s*\)/ + ) + assert.match(source, /saveButtonLabel/) +}) + +test('shows a post-create hint after the first successful save', () => { + assert.match(source, /const isPostCreateSession = computed\(\(\) => !!savedAgent\.value\)/) + assert.match(source, /settings-footer-note/) + assert.match(source, /agent\.editor\.postCreateHint\.title/) +}) diff --git a/frontend/src/views/agent/AgentEditorModal.vue b/frontend/src/views/agent/AgentEditorModal.vue index 0ebb06e5..2561e9c8 100644 --- a/frontend/src/views/agent/AgentEditorModal.vue +++ b/frontend/src/views/agent/AgentEditorModal.vue @@ -75,7 +75,7 @@
-

{{ $t('integrations.agentEditor.desc') }}

+

{{ isPostCreateSession ? $t('agent.editor.postCreateHint.integrationDesc') : $t('integrations.agentEditor.desc') }}

@@ -1612,13 +1612,22 @@
@@ -1714,6 +1723,12 @@ const emit = defineEmits<{ const savedAgent = ref(null); const editorMode = computed(() => (savedAgent.value ? 'edit' : props.mode)); const editorAgent = computed(() => savedAgent.value ?? props.agent ?? null); +const isPostCreateSession = computed(() => !!savedAgent.value); +const saveButtonLabel = computed(() => + editorMode.value === 'create' + ? t('agent.editor.buttons.create') + : t('agent.editor.buttons.saveAndClose') +); const copyAgentId = async () => { const id = editorAgent.value?.id; @@ -4267,12 +4282,15 @@ const handleSave = async () => { savedAgent.value = created; formData.value.id = created.id; markContextualGuideDone('agentCreate') + currentSection.value = 'basic'; + void loadAgentIntegrationCounts(created.id); MessagePlugin.success(t('agent.messages.created')); emit('success', created); } else { await updateAgent(formData.value.id, formData.value); MessagePlugin.success(t('agent.messages.updated')); emit('success'); + handleClose(); } } catch (e: any) { MessagePlugin.error(e?.message || t('agent.messages.saveFailed')); @@ -4928,12 +4946,45 @@ const handleSave = async () => { padding: 12px 40px; border-top: 1px solid var(--td-component-stroke); display: flex; + align-items: center; justify-content: flex-end; - gap: 12px; + gap: 16px; flex-shrink: 0; background-color: var(--td-bg-color-container); } +.settings-footer-note { + margin: 0; + margin-right: auto; + flex: 1; + min-width: 0; + display: flex; + align-items: flex-start; + gap: 6px; + font-size: 13px; + line-height: 20px; + color: var(--td-text-color-secondary); + + strong { + margin-right: 4px; + color: var(--td-text-color-primary); + font-weight: 500; + } + + &__icon { + flex-shrink: 0; + margin-top: 2px; + font-size: 14px; + color: var(--td-success-color); + } +} + +.settings-footer-actions { + display: flex; + gap: 12px; + flex-shrink: 0; +} + /* 滚动条:与设置弹窗一致 */ .settings-nav::-webkit-scrollbar, .content-wrapper::-webkit-scrollbar { diff --git a/frontend/src/views/knowledge/KnowledgeBaseEditorModal.test.mjs b/frontend/src/views/knowledge/KnowledgeBaseEditorModal.test.mjs new file mode 100644 index 00000000..0e75df7b --- /dev/null +++ b/frontend/src/views/knowledge/KnowledgeBaseEditorModal.test.mjs @@ -0,0 +1,32 @@ +import assert from 'node:assert/strict' +import { readFileSync } from 'node:fs' +import test from 'node:test' + +const source = readFileSync(new URL('./KnowledgeBaseEditorModal.vue', import.meta.url), 'utf8') + +test('editing a knowledge base closes the editor after a successful save', () => { + assert.match(source, /emit\('success', kbId\)\s*handleClose\(\)/) +}) + +test('the first successful create stays open for follow-up configuration', () => { + const createBranch = source.match( + /if \(editorMode\.value === 'create'\) \{([\s\S]*?)^\s{4}\} else \{/m + )?.[1] + + assert.ok(createBranch, 'expected to find the create branch') + assert.doesNotMatch(createBranch, /handleClose\(\)/) + assert.match(createBranch, /savedKbId\.value = result\.data\.id/) +}) + +test('save button labels distinguish create from save-and-close', () => { + assert.match( + source, + /const saveButtonLabel = computed\(\(\) =>\s*editorMode\.value === 'create'\s*\? t\('knowledgeEditor\.buttons\.create'\)\s*: t\('knowledgeEditor\.buttons\.saveAndClose'\)\s*\)/ + ) +}) + +test('shows a post-create hint after the first successful save', () => { + assert.match(source, /const isPostCreateSession = computed\(\(\) => !!savedKbId\.value\)/) + assert.match(source, /settings-footer-note/) + assert.match(source, /knowledgeEditor\.postCreateHint\.followUpDesc/) +}) diff --git a/frontend/src/views/knowledge/KnowledgeBaseEditorModal.vue b/frontend/src/views/knowledge/KnowledgeBaseEditorModal.vue index 2eedad70..0b640e93 100644 --- a/frontend/src/views/knowledge/KnowledgeBaseEditorModal.vue +++ b/frontend/src/views/knowledge/KnowledgeBaseEditorModal.vue @@ -14,7 +14,7 @@
@@ -495,8 +504,19 @@ const emit = defineEmits<{ (e: 'success', kbId: string): void }>() +/** 首次保存创建成功后留在弹窗内,继续配置共享等设置 */ +const savedKbId = ref(null) +const editorMode = computed(() => (savedKbId.value ? 'edit' : props.mode)) +const activeKbId = computed(() => savedKbId.value ?? props.kbId) +const isPostCreateSession = computed(() => !!savedKbId.value) +const saveButtonLabel = computed(() => + editorMode.value === 'create' + ? t('knowledgeEditor.buttons.create') + : t('knowledgeEditor.buttons.saveAndClose') +) + const copyKbId = async () => { - const id = props.kbId + const id = activeKbId.value if (!id) return try { @@ -556,7 +576,7 @@ const kbTenantId = ref(0) // would only see 403s if we let them try. Mirror the matrix here so // the buttons disappear instead of failing. const canShareKB = computed(() => { - if (!props.kbId) return false + if (!activeKbId.value) return false const userId = authStore.user?.id || '' if (kbCreatorId.value && userId && kbCreatorId.value === userId) return true return authStore.hasRole('admin') @@ -568,7 +588,7 @@ const isKbOwner = computed(() => { }) const canViewActivity = computed(() => { - if (props.mode !== 'edit' || !props.kbId) return false + if (editorMode.value !== 'edit' || !activeKbId.value) return false if (Number(kbTenantId.value || 0) !== Number(authStore.currentTenantId || 0)) return false return isKbOwner.value || authStore.hasRole('admin') }) @@ -614,11 +634,11 @@ const navItems = computed(() => { { key: 'graph', icon: 'chart-bubble', label: t('knowledgeEditor.sidebar.graph') }, { key: 'advanced', icon: 'setting', label: t('knowledgeEditor.sidebar.advanced') } ) - if (props.mode === 'edit' && props.kbId) { + if (editorMode.value === 'edit' && activeKbId.value) { items.push({ key: 'datasource', icon: 'cloud-download', label: t('knowledgeEditor.sidebar.datasource'), badge: dsCount.value || undefined }) } } - if (props.mode === 'edit' && props.kbId && !authStore.isLiteMode) { + if (editorMode.value === 'edit' && activeKbId.value && !authStore.isLiteMode) { items.push({ key: 'share', icon: 'share', label: t('knowledgeEditor.sidebar.share') }) } if (canViewActivity.value) { @@ -676,7 +696,7 @@ const kbCreateNeedsEmbedding = computed(() => { }) const applyDefaultModelsIfEmpty = () => { - if (!formData.value || props.mode !== 'create') return + if (!formData.value || editorMode.value !== 'create') return const pick = (type: ModelConfig['type']) => { const list = allModels.value.filter((m) => m.type === type) return list.find((m) => m.is_default) || list[0] @@ -811,14 +831,15 @@ const loadAllModels = async (force = false) => { } // 加载知识库数据(编辑模式) -const loadKBData = async () => { - if (props.mode !== 'edit' || !props.kbId) return +const loadKBData = async (kbIdOverride?: string) => { + const kbId = kbIdOverride ?? activeKbId.value + if (editorMode.value !== 'edit' || !kbId) return loading.value = true try { const [kbInfo, filesResult] = await Promise.all([ - getKnowledgeBaseById(props.kbId), - listKnowledgeFiles(props.kbId, { page: 1, page_size: 1 }) + getKnowledgeBaseById(kbId), + listKnowledgeFiles(kbId, { page: 1, page_size: 1 }) ]) if (!kbInfo || !kbInfo.data) { @@ -974,7 +995,7 @@ const handleGranularityChange = (value: string | number | boolean) => { } } -const isIndexingLocked = computed(() => props.mode === 'edit' && hasFiles.value) +const isIndexingLocked = computed(() => editorMode.value === 'edit' && hasFiles.value) const toggleVectorIndexing = () => { if (!formData.value) return @@ -1008,7 +1029,7 @@ const isWikiOnlyStrategy = computed(() => { // 仅在创建模式、用户未改过分块设置时,随索引策略自动应用/撤销 Wiki-only 预设。 // 编辑模式严格保持后端已有配置不变,避免误改。 watch(isWikiOnlyStrategy, (wikiOnly) => { - if (props.mode !== 'create') return + if (editorMode.value !== 'create') return if (!formData.value) return if (chunkingDirty.value) return const preset = wikiOnly ? WIKI_ONLY_CHUNKING_PRESET : DEFAULT_CHUNKING_PRESET @@ -1050,7 +1071,7 @@ const handleAddWikiModel = () => { const handleStorageProviderUpdate = (value: string) => { if (formData.value) { - formData.value.storageProvider = props.mode === 'create' + formData.value.storageProvider = editorMode.value === 'create' ? editorResources.resolveUsableStorageProvider(value || tenantDefaultStorageProvider.value) : (value || tenantDefaultStorageProvider.value || 'local') } @@ -1076,7 +1097,7 @@ async function loadTenantDefaultStorageProvider(force = false) { /** Resolved storage provider for create payload (never silently default to local before tenant config loads). */ function resolvedStorageProvider(): string { const explicit = formData.value?.storageProvider?.trim() - if (props.mode === 'create') { + if (editorMode.value === 'create') { return editorResources.resolveUsableStorageProvider(explicit || tenantDefaultStorageProvider.value) } if (explicit) return explicit @@ -1298,7 +1319,7 @@ const handleSubmit = async () => { // 编辑模式下,若已有文件且存储引擎发生了变化,弹窗确认 if ( - props.mode === 'edit' && + editorMode.value === 'edit' && hasFiles.value && formData.value && initialStorageProvider.value && @@ -1331,18 +1352,22 @@ const doSubmit = async () => { throw new Error(t('knowledgeEditor.messages.buildDataFailed')) } - if (props.mode === 'create') { + if (editorMode.value === 'create') { // 创建模式:一次性创建知识库及所有配置 const result: any = await createKnowledgeBase(data) if (!result.success || !result.data?.id) { throw new Error(result.message || t('knowledgeEditor.messages.createFailed')) } + savedKbId.value = result.data.id + currentSection.value = 'basic' + await loadKBData(savedKbId.value) MessagePlugin.success(t('knowledgeEditor.messages.createSuccess')) markContextualGuideDone('kbCreate') - emit('success', result.data.id) + emit('success', savedKbId.value) } else { // 编辑模式:分别更新基本信息和配置 - if (!props.kbId) { + const kbId = activeKbId.value + if (!kbId) { throw new Error(t('knowledgeEditor.messages.missingId')) } @@ -1371,7 +1396,7 @@ const doSubmit = async () => { graph_enabled: formData.value.indexingStrategy?.graphEnabled ?? false, } } - await updateKnowledgeBase(props.kbId, { + await updateKnowledgeBase(kbId, { name: data.name, description: data.description, config: updateConfig @@ -1419,7 +1444,7 @@ const doSubmit = async () => { } } - await updateKBConfig(props.kbId, config) + await updateKBConfig(kbId, config) MessagePlugin.success(t('knowledgeEditor.messages.updateSuccess')) // Check if indexing strategy changed and offer rebuild @@ -1441,7 +1466,7 @@ const doSubmit = async () => { onConfirm: async () => { dialog.destroy() try { - const result: any = await rebuildKBIndex(props.kbId!) + const result: any = await rebuildKBIndex(kbId) const count = result?.data?.document_count ?? 0 MessagePlugin.success(t('knowledgeEditor.indexing.rebuildSuccess', { count })) } catch (e) { @@ -1456,10 +1481,9 @@ const doSubmit = async () => { } } - emit('success', props.kbId) + emit('success', kbId) + handleClose() } - - handleClose() } catch (error: any) { console.error('Knowledge base operation failed:', error) // Vector-store-binding error codes from the server. Both indicate @@ -1486,6 +1510,7 @@ const doSubmit = async () => { // 重置所有状态 const resetState = () => { + savedKbId.value = null currentSection.value = 'basic' formData.value = null hasFiles.value = false @@ -1931,10 +1956,43 @@ watch( } .settings-footer { - padding: 16px 32px; + padding: 12px 40px; border-top: 1px solid var(--td-component-stroke); display: flex; + align-items: center; justify-content: flex-end; + gap: 16px; + flex-shrink: 0; +} + +.settings-footer-note { + margin: 0; + margin-right: auto; + flex: 1; + min-width: 0; + display: flex; + align-items: flex-start; + gap: 6px; + font-size: 13px; + line-height: 20px; + color: var(--td-text-color-secondary); + + strong { + margin-right: 4px; + color: var(--td-text-color-primary); + font-weight: 500; + } + + &__icon { + flex-shrink: 0; + margin-top: 2px; + font-size: 14px; + color: var(--td-success-color); + } +} + +.settings-footer-actions { + display: flex; gap: 12px; flex-shrink: 0; } diff --git a/frontend/src/views/knowledge/KnowledgeBaseList.vue b/frontend/src/views/knowledge/KnowledgeBaseList.vue index 25a3578c..0da588be 100644 --- a/frontend/src/views/knowledge/KnowledgeBaseList.vue +++ b/frontend/src/views/knowledge/KnowledgeBaseList.vue @@ -1707,7 +1707,7 @@ const handleKBEditorSuccess = (kbId: string) => { // 列表页编辑同样要让单 KB 详情缓存失效,否则侧栏 / 详情页 60s 内仍显示旧信息 chatResources.invalidateKnowledgeBaseDetail(kbId) fetchList(true).then(() => { - if (shouldOpenDetailForUploadGuide && kbId) { + if (shouldOpenDetailForUploadGuide && kbId && !uiStore.showKBEditorModal) { goDetail(kbId) } // 如果是从路由参数中获取的高亮ID,触发闪烁效果