From 01f0700b356b36c36be4c3110fc9932e9ce6a8df Mon Sep 17 00:00:00 2001 From: jacentsao Date: Wed, 16 Sep 2026 14:38:16 +0800 Subject: [PATCH] feat(datasource): add Confluence sync (#3287) * feat(datasource): add Confluence sync * fix(confluence): resume full sync and list Server pages without CQL CQL search silently truncates large spaces and can delete pages that dropped out of the index. Full-sync checkpoints now keep a deletion baseline so Asynq retries continue instead of restarting. * fix(confluence): satisfy package lint for pre-push against main * fix(confluence): parse Server page lists and keep version expand The default Server/DC edition unmarshaled /content/page as a nested envelope, so sync imported zero pages. Pagination next links also drop expand=version,space, which made later pages versionless and hid edits. * fix(confluence): classify errors and fail closed on empty listings Raw Confluence error bodies were copied into sync-log UI, and pagination next links could leave the configured context path via `..`. Empty listings against a non-empty baseline now abort instead of deleting. --------- Co-authored-by: wizardchen --- .../src/assets/img/datasource-confluence.svg | 11 + frontend/src/components/doc-content.vue | 1 + frontend/src/i18n/locales/en-US.ts | 10 + frontend/src/i18n/locales/ja-JP.ts | 10 + frontend/src/i18n/locales/ko-KR.ts | 10 + frontend/src/i18n/locales/ru-RU.ts | 10 + frontend/src/i18n/locales/zh-CN.ts | 10 + .../components/tool-results/DocumentInfo.vue | 1 + .../src/views/knowledge/KnowledgeBase.vue | 1 + .../knowledge/components/DocumentCardView.vue | 1 + .../knowledge/components/DocumentListView.vue | 1 + .../settings/DataSourceEditorDialog.vue | 71 +++- .../knowledge/settings/datasourceIcons.ts | 2 + .../application/service/datasource_service.go | 36 +- .../service/datasource_stream_test.go | 81 ++++ .../application/service/knowledge_create.go | 17 +- .../service/knowledge_create_gitlab_test.go | 32 ++ internal/container/container.go | 5 +- internal/datasource/connector.go | 13 +- .../datasource/connector/confluence/client.go | 358 ++++++++++++++++ .../confluence/client_behavior_test.go | 73 ++++ .../connector/confluence/client_pages_test.go | 121 ++++++ .../confluence/client_resolve_test.go | 17 + .../connector/confluence/client_test.go | 111 +++++ .../connector/confluence/connector.go | 343 +++++++++++++++ .../confluence/connector_stream_test.go | 389 ++++++++++++++++++ .../datasource/connector/confluence/types.go | 324 +++++++++++++++ .../connector/confluence/types_test.go | 89 ++++ internal/types/knowledge.go | 1 + 29 files changed, 2138 insertions(+), 11 deletions(-) create mode 100644 frontend/src/assets/img/datasource-confluence.svg create mode 100644 internal/datasource/connector/confluence/client.go create mode 100644 internal/datasource/connector/confluence/client_behavior_test.go create mode 100644 internal/datasource/connector/confluence/client_pages_test.go create mode 100644 internal/datasource/connector/confluence/client_resolve_test.go create mode 100644 internal/datasource/connector/confluence/client_test.go create mode 100644 internal/datasource/connector/confluence/connector.go create mode 100644 internal/datasource/connector/confluence/connector_stream_test.go create mode 100644 internal/datasource/connector/confluence/types.go create mode 100644 internal/datasource/connector/confluence/types_test.go diff --git a/frontend/src/assets/img/datasource-confluence.svg b/frontend/src/assets/img/datasource-confluence.svg new file mode 100644 index 00000000..9e5d27e6 --- /dev/null +++ b/frontend/src/assets/img/datasource-confluence.svg @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/frontend/src/components/doc-content.vue b/frontend/src/components/doc-content.vue index c11e438f..aced4cca 100644 --- a/frontend/src/components/doc-content.vue +++ b/frontend/src/components/doc-content.vue @@ -967,6 +967,7 @@ const channelLabelMap: Record = { wecom: 'knowledgeBase.channelWecom', feishu: 'knowledgeBase.channelFeishu', gitlab: 'knowledgeBase.channelGitLab', + confluence: 'knowledgeBase.channelConfluence', // Drive (云盘) connectors get their own channel so Drive docs show // "飞书云盘" / "Lark 云盘", distinct from the wiki connector's "飞书". feishu_drive: 'knowledgeBase.channelFeishuDrive', diff --git a/frontend/src/i18n/locales/en-US.ts b/frontend/src/i18n/locales/en-US.ts index 87cc0a17..c90d8a50 100755 --- a/frontend/src/i18n/locales/en-US.ts +++ b/frontend/src/i18n/locales/en-US.ts @@ -583,6 +583,7 @@ export default { channelSlack: 'Slack', channelIm: 'IM Channel', channelNotion: 'Notion', + channelConfluence: 'Confluence', channelYuque: 'Yuque', channelGitLab: 'GitLab', channelIma: 'Tencent IMA', @@ -6440,6 +6441,7 @@ export default { feishu_drive: 'Feishu Drive', lark_drive: 'Lark Drive', notion: 'Notion', + confluence: 'Confluence', yuque: 'Yuque', dingtalk: 'DingTalk Docs', rss: 'RSS / Atom Feed', @@ -6452,6 +6454,7 @@ export default { feishu_drive: 'Sync documents, spreadsheets and files from a Feishu Drive folder', lark_drive: 'Sync documents, spreadsheets and files from a Lark Drive folder (Feishu international)', notion: 'Sync pages and databases from Notion', + confluence: 'Sync spaces and pages from Confluence as Markdown', yuque: 'Sync documents from Yuque knowledge bases', dingtalk: 'Sync online documents from DingTalk knowledge bases', rss: 'Sync articles from RSS / Atom feeds', @@ -6480,6 +6483,13 @@ export default { operatorIdHint: 'Reads knowledge bases with this user’s permissions. Obtain it from the DingTalk user details API.', integrationToken: 'Integration Token', apiToken: 'API Token', + confluenceEdition: 'Edition', + confluenceEditionServer: 'Server / Data Center', + confluenceEditionCloud: 'Cloud', + confluenceBaseUrl: 'Confluence URL', + confluenceUsername: 'Username or email', + confluencePassword: 'Server/DC password', + confluenceApiToken: 'Cloud API token', imaClientId: 'IMA ClientID', imaApiKey: 'IMA APIKey', baseUrl: 'Base URL (optional)', diff --git a/frontend/src/i18n/locales/ja-JP.ts b/frontend/src/i18n/locales/ja-JP.ts index f6a4cc53..c0784eed 100644 --- a/frontend/src/i18n/locales/ja-JP.ts +++ b/frontend/src/i18n/locales/ja-JP.ts @@ -583,6 +583,7 @@ export default { channelSlack: 'Slack', channelIm: 'IMチャネル', channelNotion: 'Notion', + channelConfluence: 'Confluence', channelYuque: 'Yuque', channelGitLab: 'GitLab', channelIma: 'Tencent IMA', @@ -6440,6 +6441,7 @@ export default { feishu_drive: 'Feishu Drive', lark_drive: 'Lark Drive', notion: 'Notion', + confluence: 'Confluence', yuque: 'Yuque', dingtalk: 'DingTalkドキュメント', rss: 'RSS / Atomフィード', @@ -6452,6 +6454,7 @@ export default { feishu_drive: 'Feishu Driveのフォルダからドキュメント、スプレッドシート、ファイルを同期します', lark_drive: 'Lark Drive(Feishu国際版)のフォルダからドキュメント、スプレッドシート、ファイルを同期します', notion: 'Notionからページとデータベースを同期します', + confluence: 'Confluence のスペースとページを Markdown として同期', yuque: 'Yuqueのナレッジベースからドキュメントを同期します', dingtalk: 'DingTalkナレッジベースのオンラインドキュメントを同期', rss: 'RSS / Atomフィードから記事を同期します', @@ -6480,6 +6483,13 @@ export default { appSecret: 'App Secret', integrationToken: 'Integration Token', apiToken: 'APIトークン', + confluenceEdition: 'Confluence エディション', + confluenceEditionServer: 'Server / Data Center', + confluenceEditionCloud: 'Cloud', + confluenceBaseUrl: 'Confluence URL', + confluenceUsername: 'ユーザー名またはメールアドレス', + confluencePassword: 'Server/DC パスワード', + confluenceApiToken: 'Cloud API トークン', imaClientId: 'IMA ClientID', imaApiKey: 'IMA APIKey', baseUrl: 'ベースURL(任意)', diff --git a/frontend/src/i18n/locales/ko-KR.ts b/frontend/src/i18n/locales/ko-KR.ts index e310b619..4199aa45 100755 --- a/frontend/src/i18n/locales/ko-KR.ts +++ b/frontend/src/i18n/locales/ko-KR.ts @@ -840,6 +840,13 @@ export default { appSecret: 'App Secret', integrationToken: 'Integration Token', apiToken: 'API Token', + confluenceEdition: 'Confluence 에디션', + confluenceEditionServer: 'Server / Data Center', + confluenceEditionCloud: 'Cloud', + confluenceBaseUrl: 'Confluence URL', + confluenceUsername: '사용자 이름 또는 이메일', + confluencePassword: 'Server/DC 비밀번호', + confluenceApiToken: 'Cloud API 토큰', clientId: 'Client ID', clientSecret: 'Client Secret', operatorId: '운영자 Union ID', @@ -859,6 +866,7 @@ export default { feishu_drive: "페이슈 드라이브 폴더에서 문서, 스프레드시트, 파일 동기화", lark_drive: "Lark 드라이브 폴더에서 문서, 스프레드시트, 파일 동기화", notion: 'Notion에서 페이지 및 데이터베이스 동기화', + confluence: 'Confluence 스페이스와 페이지를 Markdown으로 동기화', yuque: '위큐 지식베이스에서 문서 동기화', dingtalk: 'DingTalk 지식베이스의 온라인 문서 동기화', ima: 'Tencent IMA 지식베이스에서 문서, 노트 및 파일 동기화 (AI 세션과 동영상 분석은 지원되지 않음)', @@ -871,6 +879,7 @@ export default { feishu_drive: "페이슈 드라이브", lark_drive: "Lark 드라이브", notion: 'Notion', + confluence: 'Confluence', yuque: '위큐 (Yuque)', dingtalk: 'DingTalk 문서', ima: 'Tencent IMA', @@ -6600,6 +6609,7 @@ export default { channelSlack: 'Slack', channelIm: 'IM 채널', channelNotion: 'Notion', + channelConfluence: 'Confluence', channelYuque: 'Yuque', channelGitLab: 'GitLab', channelIma: 'Tencent IMA', diff --git a/frontend/src/i18n/locales/ru-RU.ts b/frontend/src/i18n/locales/ru-RU.ts index e13ec971..e7256934 100755 --- a/frontend/src/i18n/locales/ru-RU.ts +++ b/frontend/src/i18n/locales/ru-RU.ts @@ -840,6 +840,13 @@ export default { appSecret: 'App Secret', integrationToken: 'Integration Token', apiToken: 'API Token', + confluenceEdition: 'Версия Confluence', + confluenceEditionServer: 'Server / Data Center', + confluenceEditionCloud: 'Cloud', + confluenceBaseUrl: 'URL Confluence', + confluenceUsername: 'Имя пользователя или эл. почта', + confluencePassword: 'Пароль Server/DC', + confluenceApiToken: 'API-токен Cloud', clientId: 'Client ID', clientSecret: 'Client Secret', operatorId: 'Union ID оператора', @@ -859,6 +866,7 @@ export default { feishu_drive: 'Синхронизация документов, таблиц и файлов из папки Feishu Drive', lark_drive: 'Синхронизация документов, таблиц и файлов из папки Lark Drive', notion: 'Синхронизация страниц и баз данных из Notion', + confluence: 'Синхронизация пространств и страниц Confluence в Markdown', yuque: 'Синхронизация документов из баз знаний Yuque', dingtalk: 'Синхронизация онлайн-документов из баз знаний DingTalk', ima: 'Синхронизация документов, заметок и файлов из баз знаний Tencent IMA (ИИ-сессии и разбор видео не поддерживаются)', @@ -871,6 +879,7 @@ export default { feishu_drive: 'Feishu Drive', lark_drive: 'Lark Drive', notion: 'Notion', + confluence: 'Confluence', yuque: 'Yuque (Юйцюэ)', dingtalk: 'Документы DingTalk', ima: 'Tencent IMA', @@ -6600,6 +6609,7 @@ export default { channelSlack: 'Slack', channelIm: 'IM канал', channelNotion: 'Notion', + channelConfluence: 'Confluence', channelYuque: 'Yuque', channelGitLab: 'GitLab', channelIma: 'Tencent IMA', diff --git a/frontend/src/i18n/locales/zh-CN.ts b/frontend/src/i18n/locales/zh-CN.ts index 487dc1a9..22d560e4 100755 --- a/frontend/src/i18n/locales/zh-CN.ts +++ b/frontend/src/i18n/locales/zh-CN.ts @@ -842,6 +842,13 @@ export default { appSecret: 'App Secret', integrationToken: 'Integration Token', apiToken: 'API Token', + confluenceEdition: 'Confluence 版本', + confluenceEditionServer: 'Server / Data Center', + confluenceEditionCloud: 'Cloud', + confluenceBaseUrl: 'Confluence 地址', + confluenceUsername: '用户名或邮箱', + confluencePassword: 'Server/DC 密码', + confluenceApiToken: 'Cloud API 令牌', clientId: 'Client ID', clientSecret: 'Client Secret', operatorId: '操作人 Union ID', @@ -861,6 +868,7 @@ export default { feishu_drive: "同步飞书云盘文件夹中的文档、表格、文件", lark_drive: "同步 Lark 云盘文件夹中的文档、表格、文件(飞书国际版)", notion: '同步 Notion 中的页面和数据库', + confluence: '将 Confluence 空间和页面同步为 Markdown', yuque: '同步语雀知识库中的文档', dingtalk: '同步钉钉知识库中的在线文档', ima: '同步腾讯 IMA 知识库中的文档、笔记与文件(暂不支持 AI 会话与视频解析)', @@ -873,6 +881,7 @@ export default { feishu_drive: "飞书云盘", lark_drive: "Lark 云盘", notion: 'Notion', + confluence: 'Confluence', yuque: '语雀', dingtalk: '钉钉文档', ima: '腾讯 IMA', @@ -6602,6 +6611,7 @@ export default { channelSlack: 'Slack', channelIm: 'IM 渠道', channelNotion: 'Notion', + channelConfluence: 'Confluence', channelYuque: '语雀', channelGitLab: 'GitLab', channelIma: '腾讯 IMA', diff --git a/frontend/src/views/chat/components/tool-results/DocumentInfo.vue b/frontend/src/views/chat/components/tool-results/DocumentInfo.vue index 8fe01dec..e08e941e 100644 --- a/frontend/src/views/chat/components/tool-results/DocumentInfo.vue +++ b/frontend/src/views/chat/components/tool-results/DocumentInfo.vue @@ -109,6 +109,7 @@ const channelLabelMap: Record = { wecom: 'knowledgeBase.channelWecom', feishu: 'knowledgeBase.channelFeishu', gitlab: 'knowledgeBase.channelGitLab', + confluence: 'knowledgeBase.channelConfluence', dingtalk: 'knowledgeBase.channelDingtalk', slack: 'knowledgeBase.channelSlack', im: 'knowledgeBase.channelIm', diff --git a/frontend/src/views/knowledge/KnowledgeBase.vue b/frontend/src/views/knowledge/KnowledgeBase.vue index 86eda162..d9d3c1c8 100644 --- a/frontend/src/views/knowledge/KnowledgeBase.vue +++ b/frontend/src/views/knowledge/KnowledgeBase.vue @@ -601,6 +601,7 @@ const sourceOptions = computed(() => [ { label: t('knowledgeBase.channelFeishuDrive'), value: 'feishu_drive' }, { label: t('knowledgeBase.channelNotion'), value: 'notion' }, { label: t('knowledgeBase.channelYuque'), value: 'yuque' }, + { label: t('knowledgeBase.channelConfluence'), value: 'confluence' }, { label: t('knowledgeBase.channelGitLab'), value: 'gitlab' }, { label: t('knowledgeBase.channelIma'), value: 'ima' }, { label: t('knowledgeBase.channelWechat'), value: 'wechat' }, diff --git a/frontend/src/views/knowledge/components/DocumentCardView.vue b/frontend/src/views/knowledge/components/DocumentCardView.vue index 92e98de8..ec55b077 100644 --- a/frontend/src/views/knowledge/components/DocumentCardView.vue +++ b/frontend/src/views/knowledge/components/DocumentCardView.vue @@ -155,6 +155,7 @@ const channelLabelMap: Record = { wecom: 'knowledgeBase.channelWecom', feishu: 'knowledgeBase.channelFeishu', gitlab: 'knowledgeBase.channelGitLab', + confluence: 'knowledgeBase.channelConfluence', dingtalk: 'knowledgeBase.channelDingtalk', slack: 'knowledgeBase.channelSlack', im: 'knowledgeBase.channelIm', diff --git a/frontend/src/views/knowledge/components/DocumentListView.vue b/frontend/src/views/knowledge/components/DocumentListView.vue index 2fb5fff8..c526310e 100644 --- a/frontend/src/views/knowledge/components/DocumentListView.vue +++ b/frontend/src/views/knowledge/components/DocumentListView.vue @@ -114,6 +114,7 @@ const getSourceInfo = (item: KnowledgeItem): { icon: string; label: string } => if (ch === 'lark_drive') return { icon: 'cloud-download', label: t('knowledgeBase.channelLarkDrive') }; if (ch === 'notion') return { icon: 'cloud-download', label: t('knowledgeBase.channelNotion') }; if (ch === 'yuque') return { icon: 'cloud-download', label: t('knowledgeBase.channelYuque') }; + if (ch === 'confluence') return { icon: 'cloud-download', label: t('knowledgeBase.channelConfluence') }; if (ch === 'gitlab') return { icon: 'cloud-download', label: t('knowledgeBase.channelGitLab') }; if (ch === 'ima') return { icon: 'cloud-download', label: t('knowledgeBase.channelIma') }; if (ch === 'wechat') return { icon: 'cloud-download', label: t('knowledgeBase.channelWechat') }; diff --git a/frontend/src/views/knowledge/settings/DataSourceEditorDialog.vue b/frontend/src/views/knowledge/settings/DataSourceEditorDialog.vue index d7bc046d..746a7608 100644 --- a/frontend/src/views/knowledge/settings/DataSourceEditorDialog.vue +++ b/frontend/src/views/knowledge/settings/DataSourceEditorDialog.vue @@ -159,9 +159,33 @@ function needsConnectionTest(): boolean { return !(isEdit.value && credentialsConfigured.value && !replaceCredentialsMode.value) } +function hydrateConfluenceCredentialsFromSettings() { + if (form.value.type !== 'confluence') return + const settings = form.value.config.settings || {} + const creds = form.value.config.credentials || {} + form.value.config.credentials = { + ...creds, + edition: creds.edition || settings.edition || 'server', + base_url: creds.base_url || settings.base_url || '', + username: creds.username || settings.username || '', + } +} + +function syncConfluencePublicFieldsToSettings() { + if (form.value.type !== 'confluence') return + const creds = form.value.config.credentials || {} + form.value.config.settings = { + ...(form.value.config.settings || {}), + ...(creds.edition ? { edition: creds.edition } : {}), + ...(creds.base_url ? { base_url: creds.base_url } : {}), + ...(creds.username ? { username: creds.username } : {}), + } +} + function enterReplaceCredentials() { pendingRemoveCredentials.value = false replaceCredentialsMode.value = true + hydrateConfluenceCredentialsFromSettings() testResult.value = '' testErrorMsg.value = '' } @@ -585,6 +609,20 @@ const connectorDefs = computed(() => [ { key: 'api_key', labelKey: 'datasource.field.integrationToken', placeholder: 'ntn_xxxx', secret: true }, ], }, + { + type: 'confluence', + available: true, + docUrl: 'https://developer.atlassian.com/cloud/confluence/rest/', + permissionDocUrl: 'https://developer.atlassian.com/cloud/confluence/rest/', + permissionPageUrl: 'https://id.atlassian.com/manage-profile/security/api-tokens', + requiredPermissions: [], + fields: [ + { key: 'base_url', labelKey: 'datasource.field.confluenceBaseUrl', placeholder: 'https://confluence.example.com or https://team.atlassian.net/wiki' }, + { key: 'username', labelKey: 'datasource.field.confluenceUsername', placeholder: 'name or email' }, + { key: 'password', labelKey: 'datasource.field.confluencePassword', placeholder: 'Server/DC password', secret: true }, + { key: 'api_token', labelKey: 'datasource.field.confluenceApiToken', placeholder: 'Cloud API token', secret: true }, + ], + }, { type: 'yuque', available: true, @@ -655,6 +693,17 @@ const connectorDefs = computed(() => [ const currentDef = computed(() => connectorDefs.value.find(d => d.type === form.value.type)) +const displayedCredentialFields = computed(() => { + const fields = currentDef.value?.fields || [] + if (form.value.type !== "confluence") return fields + + return fields.filter((field) => { + if (field.key === "password") return form.value.config.credentials.edition !== "cloud" + if (field.key === "api_token") return form.value.config.credentials.edition === "cloud" + return true + }) +}) + // --- Drawer lifecycle --- watch(visible, async (v) => { if (!v) { @@ -783,7 +832,10 @@ function selectType(def: ConnectorDef) { if (!def.available) return form.value.type = def.type form.value.name = t(`datasource.connector.${def.type}`) - form.value.config.credentials = {} + form.value.config.credentials = def.type === "confluence" ? { edition: "server" } : {} + if (def.type === 'confluence') { + form.value.config.settings = { ...form.value.config.settings, edition: 'server' } + } if (isGitLabConnector(def.type)) addGitLabProject() rssAuthHeaders.value = [] step.value = 1 @@ -792,9 +844,10 @@ function selectType(def: ConnectorDef) { // --- Test connection --- async function testConnection() { syncRssAuthHeadersToCredentials() + syncConfluencePublicFieldsToSettings() if (!validateRssFeedUrls()) return if (!isEdit.value || !credentialsConfigured.value || replaceCredentialsMode.value) { - const fields = currentDef.value?.fields || [] + const fields = displayedCredentialFields.value for (const f of fields) { if (f.optional || f.fieldType === 'custom_headers') continue if (!form.value.config.credentials[f.key]) { @@ -839,6 +892,7 @@ async function testConnection() { async function loadResources() { loadingResources.value = true try { + syncConfluencePublicFieldsToSettings() if (!tempDsId.value) { const res = await createDataSource({ ...form.value, @@ -993,7 +1047,7 @@ function validateStep1Fields(): boolean { return true } - const fields = currentDef.value?.fields || [] + const fields = displayedCredentialFields.value for (const f of fields) { if (f.optional || f.fieldType === 'custom_headers') continue if (!form.value.config.credentials[f.key]) { @@ -1060,6 +1114,7 @@ function prevStep() { // validator happy. function buildConfigPayload(): Record { syncGitLabProjectsToSettings() + syncConfluencePublicFieldsToSettings() return { credentials: isEdit.value ? {} : { ...form.value.config.credentials }, resource_ids: form.value.config.resource_ids, @@ -1073,6 +1128,7 @@ function buildConfigPayload(): Record { async function commitCredentialsIfNeeded(dsId: string): Promise { if (!isEdit.value || !replaceCredentialsMode.value) return true syncRssAuthHeadersToCredentials() + syncConfluencePublicFieldsToSettings() const filled = Object.entries(form.value.config.credentials).filter( ([, v]) => typeof v === 'string' ? v !== '' : v != null, ) @@ -1500,8 +1556,15 @@ const drawerConfirmText = computed(() => {