From 1f87cd87521626a9c2a61edf6a3f16b9fdf0e1ca Mon Sep 17 00:00:00 2001 From: Wu Yue Date: Wed, 9 Jul 2025 20:55:31 +0800 Subject: [PATCH] feat(core): add onOpenDoc handler for AFFiNE Intelligence page (#13118) Close [AI-240](https://linear.app/affine-design/issue/AI-240) ## Summary by CodeRabbit * **New Features** * Enabled opening specific documents directly from the chat toolbar, automatically displaying the document in the workbench and focusing the chat tab in the sidebar. --- .../core/src/desktop/pages/workspace/chat/index.tsx | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/frontend/core/src/desktop/pages/workspace/chat/index.tsx b/packages/frontend/core/src/desktop/pages/workspace/chat/index.tsx index f40516bef7..919dfcfc46 100644 --- a/packages/frontend/core/src/desktop/pages/workspace/chat/index.tsx +++ b/packages/frontend/core/src/desktop/pages/workspace/chat/index.tsx @@ -17,7 +17,9 @@ import { ViewBody, ViewHeader, ViewIcon, + ViewService, ViewTitle, + WorkbenchService, } from '@affine/core/modules/workbench'; import { WorkspaceService } from '@affine/core/modules/workspace'; import { useI18n } from '@affine/i18n'; @@ -212,6 +214,14 @@ export const Component = () => { await togglePin(); }; + tool.onOpenDoc = (docId: string, sessionId: string) => { + const { workbench } = framework.get(WorkbenchService); + const viewService = framework.get(ViewService); + workbench.open(`/${docId}?sessionId=${sessionId}`, { at: 'active' }); + workbench.openSidebar(); + viewService.view.activeSidebarTab('chat'); + }; + // initial props if (!chatTool) { // mount @@ -228,6 +238,7 @@ export const Component = () => { togglePin, workspaceId, confirmModal, + framework, ]); const onChatContainerRef = useCallback((node: HTMLDivElement) => {