diff --git a/package.json b/package.json index eed65757c6..c535140251 100644 --- a/package.json +++ b/package.json @@ -62,6 +62,7 @@ "@libsql/win32-x64-msvc": "^0.4.7", "@strongtz/win32-arm64-msvc": "^0.4.7", "jsdom": "26.1.0", + "notion-helper": "^1.3.22", "os-proxy-config": "^1.1.2", "selection-hook": "^0.9.23", "turndown": "7.2.0" diff --git a/src/renderer/src/i18n/locales/en-us.json b/src/renderer/src/i18n/locales/en-us.json index e80d8015e7..74d4e2428d 100644 --- a/src/renderer/src/i18n/locales/en-us.json +++ b/src/renderer/src/i18n/locales/en-us.json @@ -653,8 +653,7 @@ "group.delete.content": "Deleting a group message will delete the user's question and all assistant's answers", "group.delete.title": "Delete Group Message", "ignore.knowledge.base": "Web search mode is enabled, ignore knowledge base", - "info.notion.block_reach_limit": "Dialogue too long, exporting to Notion in pages", - "loading.notion.exporting_progress": "Exporting to Notion ({{current}}/{{total}})...", + "loading.notion.exporting_progress": "Exporting to Notion ...", "loading.notion.preparing": "Preparing to export to Notion...", "mention.title": "Switch model answer", "message.code_style": "Code style", diff --git a/src/renderer/src/i18n/locales/ja-jp.json b/src/renderer/src/i18n/locales/ja-jp.json index afa7c9c0fa..5e9b02e2f6 100644 --- a/src/renderer/src/i18n/locales/ja-jp.json +++ b/src/renderer/src/i18n/locales/ja-jp.json @@ -651,8 +651,7 @@ "group.delete.content": "分組メッセージを削除するとユーザーの質問と助け手の回答がすべて削除されます", "group.delete.title": "分組メッセージを削除", "ignore.knowledge.base": "インターネットモードが有効になっています。ナレッジベースを無視します", - "info.notion.block_reach_limit": "会話が長すぎます。Notionにページごとにエクスポートしています", - "loading.notion.exporting_progress": "Notionにエクスポート中 ({{current}}/{{total}})...", + "loading.notion.exporting_progress": "Notionにエクスポート中 ...", "loading.notion.preparing": "Notionへのエクスポートを準備中...", "mention.title": "モデルを切り替える", "message.code_style": "コードスタイル", diff --git a/src/renderer/src/i18n/locales/ru-ru.json b/src/renderer/src/i18n/locales/ru-ru.json index 93737d666f..601f965f8a 100644 --- a/src/renderer/src/i18n/locales/ru-ru.json +++ b/src/renderer/src/i18n/locales/ru-ru.json @@ -652,8 +652,7 @@ "group.delete.content": "Удаление группы сообщений удалит пользовательский вопрос и все ответы помощника", "group.delete.title": "Удалить группу сообщений", "ignore.knowledge.base": "Режим сети включен, игнорировать базу знаний", - "info.notion.block_reach_limit": "Диалог слишком длинный, экспортируется в Notion по страницам", - "loading.notion.exporting_progress": "Экспорт в Notion ({{current}}/{{total}})...", + "loading.notion.exporting_progress": "Экспорт в Notion ...", "loading.notion.preparing": "Подготовка к экспорту в Notion...", "mention.title": "Переключить модель ответа", "message.code_style": "Стиль кода", diff --git a/src/renderer/src/i18n/locales/zh-cn.json b/src/renderer/src/i18n/locales/zh-cn.json index 672054ec82..c141207bae 100644 --- a/src/renderer/src/i18n/locales/zh-cn.json +++ b/src/renderer/src/i18n/locales/zh-cn.json @@ -653,8 +653,7 @@ "group.delete.content": "删除分组消息会删除用户提问和所有助手的回答", "group.delete.title": "删除分组消息", "ignore.knowledge.base": "联网模式开启,忽略知识库", - "info.notion.block_reach_limit": "对话过长,正在分段导出到Notion", - "loading.notion.exporting_progress": "正在导出到Notion ({{current}}/{{total}})...", + "loading.notion.exporting_progress": "正在导出到Notion ...", "loading.notion.preparing": "正在准备导出到Notion...", "mention.title": "切换模型回答", "message.code_style": "代码风格", diff --git a/src/renderer/src/i18n/locales/zh-tw.json b/src/renderer/src/i18n/locales/zh-tw.json index 61b96c6d2b..e439528328 100644 --- a/src/renderer/src/i18n/locales/zh-tw.json +++ b/src/renderer/src/i18n/locales/zh-tw.json @@ -653,8 +653,7 @@ "group.delete.content": "刪除分組訊息會刪除使用者提問和所有助手的回答", "group.delete.title": "刪除分組訊息", "ignore.knowledge.base": "網路模式開啟,忽略知識庫", - "info.notion.block_reach_limit": "對話過長,自動分頁匯出到 Notion", - "loading.notion.exporting_progress": "正在匯出到 Notion ({{current}}/{{total}})...", + "loading.notion.exporting_progress": "正在匯出到 Notion ...", "loading.notion.preparing": "正在準備匯出到 Notion...", "mention.title": "切換模型回答", "message.code_style": "程式碼風格", diff --git a/src/renderer/src/services/MessagesService.ts b/src/renderer/src/services/MessagesService.ts index 4db3060880..f4e764f4cb 100644 --- a/src/renderer/src/services/MessagesService.ts +++ b/src/renderer/src/services/MessagesService.ts @@ -214,7 +214,11 @@ export async function getMessageTitle(message: Message, length = 30): Promise { return markdownToBlocks(markdown) } -const splitNotionBlocks = (blocks: any[]) => { - // Notion API限制单次传输100块 - const notionSplitSize = 95 - - const pages: any[][] = [] - let currentPage: any[] = [] - - blocks.forEach((block) => { - if (currentPage.length >= notionSplitSize) { - window.message.info({ content: i18n.t('message.info.notion.block_reach_limit'), key: 'notion-block-reach-limit' }) - pages.push(currentPage) - currentPage = [] - } - currentPage.push(block) - }) - - if (currentPage.length > 0) { - pages.push(currentPage) - } - - return pages -} - const convertThinkingToNotionBlocks = async (thinkingContent: string): Promise => { if (!thinkingContent.trim()) { return [] @@ -306,6 +284,8 @@ const executeNotionExport = async (title: string, allBlocks: any[]): Promise 1) { - window.message.loading({ - content: i18n.t('message.loading.notion.exporting_progress', { - current: i + 1, - total: blockPages.length - }), - key: 'notion-export-progress' - }) - } else { - window.message.loading({ - content: i18n.t('message.loading.notion.preparing'), - key: 'notion-export-progress' - }) - } - - if (i === 0) { - // 创建主页面 - const response = await notion.pages.create({ - parent: { database_id: notionDatabaseID }, - properties: { - [store.getState().settings.notionPageNameKey || 'Name']: { - title: [{ text: { content: title } }] - } - }, - children: pageBlocks - }) - mainPageResponse = response - parentBlockId = response.id - } else { - // 追加后续页面的块到主页面 - if (!parentBlockId) { - throw new Error('Parent block ID is null') + const response = await notion.pages.create({ + parent: { database_id: notionDatabaseID }, + properties: { + [store.getState().settings.notionPageNameKey || 'Name']: { + title: [{ text: { content: title } }] } - await notion.blocks.children.append({ - block_id: parentBlockId, - children: pageBlocks - }) } + }) + mainPageResponse = response + parentBlockId = response.id + window.message.destroy('notion-preparing') + window.message.loading({ + content: i18n.t('message.loading.notion.exporting_progress'), + key: 'notion-exporting', + duration: 0 + }) + if (allBlocks.length > 0) { + await appendBlocks({ + block_id: parentBlockId, + children: allBlocks, + client: notion + }) } - - const messageKey = blockPages.length > 1 ? 'notion-export-progress' : 'notion-success' - window.message.success({ content: i18n.t('message.success.notion.export'), key: messageKey }) + window.message.destroy('notion-exporting') + window.message.success({ content: i18n.t('message.success.notion.export'), key: 'notion-success' }) return mainPageResponse } catch (error: any) { window.message.error({ content: i18n.t('message.error.notion.export'), key: 'notion-export-progress' }) diff --git a/src/renderer/src/utils/messageUtils/find.ts b/src/renderer/src/utils/messageUtils/find.ts index fa6c8cd668..106f2725ab 100644 --- a/src/renderer/src/utils/messageUtils/find.ts +++ b/src/renderer/src/utils/messageUtils/find.ts @@ -133,7 +133,10 @@ export const getCitationContent = (message: Message): string => { return citationBlocks .map((block) => formatCitationsFromBlock(block)) .flat() - .map((citation) => `[${citation.number}] [${citation.title || citation.url}](${citation.url})`) + .map( + (citation) => + `[${citation.number}] [${citation.title || citation.url.slice(0, 1999)}](${citation.url.slice(0, 1999)})` + ) .join('\n\n') } diff --git a/yarn.lock b/yarn.lock index 38b82f8c93..ad87138f87 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5682,6 +5682,7 @@ __metadata: mime: "npm:^4.0.4" motion: "npm:^12.10.5" node-stream-zip: "npm:^1.15.0" + notion-helper: "npm:^1.3.22" npx-scope-finder: "npm:^1.2.0" officeparser: "npm:^4.1.1" openai: "patch:openai@npm%3A5.1.0#~/.yarn/patches/openai-npm-5.1.0-0e7b3ccb07.patch" @@ -13861,6 +13862,18 @@ __metadata: languageName: node linkType: hard +"notion-helper@npm:^1.3.22": + version: 1.3.22 + resolution: "notion-helper@npm:1.3.22" + peerDependencies: + "@notionhq/client": ^2.0.0 + peerDependenciesMeta: + "@notionhq/client": + optional: true + checksum: 10c0/4afad1d6610ec910fe3fba0cb204431a1e5f3b45b5294c5ac3c0108611859a5919597e0400f500550fad709d291b7931cfe2766a49eb59638305584b90c02463 + languageName: node + linkType: hard + "npm-run-path@npm:^5.1.0": version: 5.3.0 resolution: "npm-run-path@npm:5.3.0"