fix(core): open ai chat for first time (#7291)

There are two issues here:

1. open right sidebar with chat
2. notify chat-panel of selected content

The second issue will be fixed in a subsequent PR.
This commit is contained in:
fundon 2024-06-21 01:52:29 +00:00 committed by Fangdun Tsai
parent bf0cba31d3
commit 92be6b2ff7
No known key found for this signature in database
GPG Key ID: C4E964E8E5E3A7BF
7 changed files with 9 additions and 2 deletions

View File

@ -401,6 +401,7 @@ const OthersAIGroup: AIItemGroupConfig = {
icon: CommentIcon, icon: CommentIcon,
handler: host => { handler: host => {
const panel = getAIPanel(host); const panel = getAIPanel(host);
AIProvider.slots.requestOpenWithChat.emit();
AIProvider.slots.requestContinueWithAIInChat.emit({ host }); AIProvider.slots.requestContinueWithAIInChat.emit({ host });
panel.hide(); panel.hide();
}, },
@ -410,6 +411,7 @@ const OthersAIGroup: AIItemGroupConfig = {
icon: ChatWithAIIcon, icon: ChatWithAIIcon,
handler: host => { handler: host => {
const panel = getAIPanel(host); const panel = getAIPanel(host);
AIProvider.slots.requestOpenWithChat.emit();
AIProvider.slots.requestContinueInChat.emit({ AIProvider.slots.requestContinueInChat.emit({
host: host, host: host,
show: true, show: true,

View File

@ -463,6 +463,7 @@ export function actionToResponse<T extends keyof BlockSuitePresets.AIActions>(
handler: () => { handler: () => {
reportResponse('result:continue-in-chat'); reportResponse('result:continue-in-chat');
const panel = getAIPanel(host); const panel = getAIPanel(host);
AIProvider.slots.requestOpenWithChat.emit();
AIProvider.slots.requestContinueInChat.emit({ AIProvider.slots.requestContinueInChat.emit({
host: host, host: host,
show: true, show: true,

View File

@ -233,6 +233,7 @@ export function buildTextResponseConfig<
icon: ChatWithAIIcon, icon: ChatWithAIIcon,
handler: () => { handler: () => {
reportResponse('result:continue-in-chat'); reportResponse('result:continue-in-chat');
AIProvider.slots.requestOpenWithChat.emit();
AIProvider.slots.requestContinueInChat.emit({ AIProvider.slots.requestContinueInChat.emit({
host: panel.host, host: panel.host,
show: true, show: true,

View File

@ -105,6 +105,7 @@ const othersGroup: AIItemGroupConfig = {
showWhen: () => true, showWhen: () => true,
handler: host => { handler: host => {
const panel = getAIPanel(host); const panel = getAIPanel(host);
AIProvider.slots.requestOpenWithChat.emit();
AIProvider.slots.requestContinueWithAIInChat.emit({ AIProvider.slots.requestContinueWithAIInChat.emit({
host, host,
mode: 'edgeless', mode: 'edgeless',
@ -118,6 +119,7 @@ const othersGroup: AIItemGroupConfig = {
showWhen: () => true, showWhen: () => true,
handler: host => { handler: host => {
const panel = getAIPanel(host); const panel = getAIPanel(host);
AIProvider.slots.requestOpenWithChat.emit();
AIProvider.slots.requestContinueInChat.emit({ AIProvider.slots.requestContinueInChat.emit({
host: host, host: host,
show: true, show: true,

View File

@ -80,6 +80,7 @@ export class AIProvider {
private readonly slots = { private readonly slots = {
// use case: when user selects "continue in chat" in an ask ai result panel // use case: when user selects "continue in chat" in an ask ai result panel
// do we need to pass the context to the chat panel? // do we need to pass the context to the chat panel?
requestOpenWithChat: new Slot(),
requestContinueInChat: new Slot<{ host: EditorHost; show: boolean }>(), requestContinueInChat: new Slot<{ host: EditorHost; show: boolean }>(),
requestContinueWithAIInChat: new Slot<{ requestContinueWithAIInChat: new Slot<{
host: EditorHost; host: EditorHost;

View File

@ -73,7 +73,7 @@ const DocPreview = forwardRef<
}, [docId, docs.list, resolvedMode, mode]); }, [docId, docs.list, resolvedMode, mode]);
useEffect(() => { useEffect(() => {
const disposable = AIProvider.slots.requestContinueInChat.on(() => { const disposable = AIProvider.slots.requestOpenWithChat.on(() => {
if (doc) { if (doc) {
workbench.openPage(doc.id); workbench.openPage(doc.id);
peekView.close(); peekView.close();

View File

@ -106,7 +106,7 @@ const DetailPageImpl = memo(function DetailPageImpl() {
}, [editor, isActiveView, setActiveBlockSuiteEditor]); }, [editor, isActiveView, setActiveBlockSuiteEditor]);
useEffect(() => { useEffect(() => {
AIProvider.slots.requestContinueInChat.on(() => { AIProvider.slots.requestOpenWithChat.on(() => {
rightSidebar.open(); rightSidebar.open();
if (activeTabName !== 'chat') { if (activeTabName !== 'chat') {
setActiveTabName('chat'); setActiveTabName('chat');