diff --git a/packages/frontend/core/src/blocksuite/presets/ai/actions/doc-handler.ts b/packages/frontend/core/src/blocksuite/presets/ai/actions/doc-handler.ts index 345219adbede8..76e7fd9bd7352 100644 --- a/packages/frontend/core/src/blocksuite/presets/ai/actions/doc-handler.ts +++ b/packages/frontend/core/src/blocksuite/presets/ai/actions/doc-handler.ts @@ -181,10 +181,6 @@ function updateAIPanelConfig( config.errorStateConfig = buildErrorConfig(aiPanel); config.copy = buildCopyConfig(aiPanel); config.discardCallback = () => { - getTracker(host).action_panel.discardAction({ - action: id, - control: 'discard_button', - }); reportResponse('result:discard'); }; } @@ -205,7 +201,7 @@ export function actionToHandler( if (!blocks || blocks.length === 0) return; const block = blocks.at(-1); assertExists(block); - getTracker(host).action_panel.invokeAction({ action: id }); + getTracker(host, false).invokeAction({ action: id }); aiPanel.toggle(block, 'placeholder'); }; } diff --git a/packages/frontend/core/src/blocksuite/presets/ai/actions/edgeless-handler.ts b/packages/frontend/core/src/blocksuite/presets/ai/actions/edgeless-handler.ts index 1543248a7fd3b..2879090b6781d 100644 --- a/packages/frontend/core/src/blocksuite/presets/ai/actions/edgeless-handler.ts +++ b/packages/frontend/core/src/blocksuite/presets/ai/actions/edgeless-handler.ts @@ -394,10 +394,6 @@ function updateEdgelessAIPanelConfig< }, }; config.discardCallback = () => { - getTracker(host).action_panel.discardAction({ - action: id, - control: 'discard_button', - }); reportResponse('result:discard'); }; config.hideCallback = () => { @@ -516,7 +512,7 @@ export function actionToHandler( togglePanel() .then(isEmpty => { - getTracker(host).action_panel.invokeAction({ action: id }); + getTracker(host, false).invokeAction({ action: id }); aiPanel.toggle( referenceElement, isEmpty ? undefined : 'placeholder', diff --git a/packages/frontend/core/src/blocksuite/presets/ai/actions/edgeless-response.ts b/packages/frontend/core/src/blocksuite/presets/ai/actions/edgeless-response.ts index b7f9cefe2c1a3..785f31bca47a0 100644 --- a/packages/frontend/core/src/blocksuite/presets/ai/actions/edgeless-response.ts +++ b/packages/frontend/core/src/blocksuite/presets/ai/actions/edgeless-response.ts @@ -89,18 +89,11 @@ export function discard(panel: AffineAIPanelWidget): AIItemConfig { }; } -export function retry( - panel: AffineAIPanelWidget, - id: T -): AIItemConfig { +export function retry(panel: AffineAIPanelWidget): AIItemConfig { return { name: 'Retry', icon: ResetIcon, handler: () => { - getTracker(panel.host).action_panel.invokeAction({ - action: id, - retry: true, - }); reportResponse('result:retry'); panel.generate(); }, @@ -149,10 +142,6 @@ export function createInsertResp( ); }, handler: () => { - getTracker(host).action_panel.acceptAction({ - action: id, - control: 'insert', - }); reportResponse('result:insert'); handler(host, ctx); const panel = getAIPanel(host); @@ -174,10 +163,6 @@ export function asCaption( return id === 'generateCaption' && !!panel.answer; }, handler: () => { - getTracker(host).action_panel.acceptAction({ - action: id, - control: 'as_caption', - }); reportResponse('result:use-as-caption'); const panel = getAIPanel(host); const caption = panel.answer; @@ -595,10 +580,6 @@ export function actionToResponse( name: 'Continue in chat', icon: ChatWithAIIcon, handler: () => { - getTracker(host).action_panel.acceptAction({ - action: id, - control: 'continue_in_chat', - }); reportResponse('result:continue-in-chat'); const panel = getAIPanel(host); AIProvider.slots.requestOpenWithChat.emit({ host }); @@ -607,7 +588,7 @@ export function actionToResponse( }, ...getInsertAndReplaceHandler(id, host, ctx, variants), asCaption(id, host), - retry(getAIPanel(host), id), + retry(getAIPanel(host)), discard(getAIPanel(host)), ], }, @@ -640,7 +621,7 @@ export function actionToErrorResponse< ): ErrorConfig { return { upgrade: () => { - getTracker(host).action_panel.discardAction({ + getTracker(host, false).discardAction({ action: id, control: 'paywall', }); @@ -648,7 +629,7 @@ export function actionToErrorResponse< panel.hide(); }, login: () => { - getTracker(host).action_panel.discardAction({ + getTracker(host, false).discardAction({ action: id, control: 'login_required', }); @@ -656,7 +637,7 @@ export function actionToErrorResponse< panel.hide(); }, cancel: () => { - getTracker(host).action_panel.discardAction({ + getTracker(host, false).discardAction({ action: id, control: 'paywall', }); @@ -669,7 +650,7 @@ export function actionToErrorResponse< }, { name: '', - items: [retry(getAIPanel(host), id), discard(getAIPanel(host))], + items: [retry(getAIPanel(host)), discard(getAIPanel(host))], }, ], }; diff --git a/packages/frontend/core/src/blocksuite/presets/ai/ai-panel.ts b/packages/frontend/core/src/blocksuite/presets/ai/ai-panel.ts index f3d2033596c24..a6825bf05780c 100644 --- a/packages/frontend/core/src/blocksuite/presets/ai/ai-panel.ts +++ b/packages/frontend/core/src/blocksuite/presets/ai/ai-panel.ts @@ -66,10 +66,6 @@ function asCaption( return id === 'generateCaption' && !!panel.answer; }, handler: () => { - getTracker(host).action_panel.acceptAction({ - action: id, - control: 'as_caption', - }); reportResponse('result:use-as-caption'); const panel = getAIPanel(host); const caption = panel.answer; @@ -87,10 +83,7 @@ function asCaption( }; } -function createNewNote( - host: EditorHost, - id?: T -): AIItemConfig { +function createNewNote(host: EditorHost): AIItemConfig { return { name: 'Create new note', icon: CreateIcon, @@ -99,10 +92,6 @@ function createNewNote( return !!panel.answer && isInsideEdgelessEditor(host); }, handler: () => { - getTracker(host).action_panel.acceptAction({ - action: id, - control: 'insert_note', - }); reportResponse('result:add-note'); // get the note block const { selectedBlocks } = getSelections(host); @@ -208,10 +197,6 @@ export function buildTextResponseConfig< showWhen: () => !!panel.answer && (!id || !INSERT_ABOVE_ACTIONS.includes(id)), handler: () => { - getTracker(host).action_panel.acceptAction({ - action: id, - control: 'insert', - }); reportResponse('result:insert'); insertAnswerBelow(panel).catch(console.error); }, @@ -222,10 +207,6 @@ export function buildTextResponseConfig< showWhen: () => !!panel.answer && !!id && INSERT_ABOVE_ACTIONS.includes(id), handler: () => { - getTracker(host).action_panel.acceptAction({ - action: id, - control: 'insert', - }); reportResponse('result:insert'); insertAnswerAbove(panel).catch(console.error); }, @@ -236,15 +217,11 @@ export function buildTextResponseConfig< icon: ReplaceIcon, showWhen: () => !!panel.answer, handler: () => { - getTracker(host).action_panel.acceptAction({ - action: id, - control: 'replace', - }); reportResponse('result:replace'); replaceWithAnswer(panel).catch(console.error); }, }, - createNewNote(host, id), + createNewNote(host), ], }, { @@ -254,10 +231,6 @@ export function buildTextResponseConfig< name: 'Continue in chat', icon: ChatWithAIIcon, handler: () => { - getTracker(host).action_panel.acceptAction({ - action: id, - control: 'continue_in_chat', - }); reportResponse('result:continue-in-chat'); AIProvider.slots.requestOpenWithChat.emit({ host }); panel.hide(); @@ -267,10 +240,6 @@ export function buildTextResponseConfig< name: 'Regenerate', icon: RetryIcon, handler: () => { - getTracker(host).action_panel.invokeAction({ - action: id, - retry: true, - }); reportResponse('result:retry'); panel.generate(); }, @@ -301,10 +270,7 @@ export function buildErrorResponseConfig< icon: ReplaceIcon, showWhen: () => !!panel.answer, handler: () => { - getTracker(host).action_panel.acceptAction({ - action: id, - control: 'replace', - }); + reportResponse('result:replace'); replaceWithAnswer(panel).catch(console.error); }, }, @@ -314,10 +280,7 @@ export function buildErrorResponseConfig< showWhen: () => !!panel.answer && (!id || !INSERT_ABOVE_ACTIONS.includes(id)), handler: () => { - getTracker(host).action_panel.acceptAction({ - action: id, - control: 'insert', - }); + reportResponse('result:insert'); insertAnswerBelow(panel).catch(console.error); }, }, @@ -327,16 +290,12 @@ export function buildErrorResponseConfig< showWhen: () => !!panel.answer && !!id && INSERT_ABOVE_ACTIONS.includes(id), handler: () => { - getTracker(host).action_panel.acceptAction({ - action: id, - control: 'insert', - }); reportResponse('result:insert'); insertAnswerAbove(panel).catch(console.error); }, }, asCaption(host, id), - createNewNote(host, id), + createNewNote(host), ], }, { @@ -347,10 +306,6 @@ export function buildErrorResponseConfig< icon: RetryIcon, showWhen: () => true, handler: () => { - getTracker(host).action_panel.invokeAction({ - action: id, - retry: true, - }); reportResponse('result:retry'); panel.generate(); }, @@ -386,7 +341,7 @@ export function buildErrorConfig( return { upgrade: () => { - getTracker(host).action_panel.discardAction({ + getTracker(host, false).discardAction({ action: id, control: 'paywall', }); @@ -394,7 +349,7 @@ export function buildErrorConfig( panel.hide(); }, login: () => { - getTracker(host).action_panel.discardAction({ + getTracker(host, false).discardAction({ action: id, control: 'login_required', }); @@ -402,7 +357,7 @@ export function buildErrorConfig( panel.hide(); }, cancel: () => { - getTracker(host).action_panel.discardAction({ + getTracker(host, false).discardAction({ action: id, control: 'paywall', }); diff --git a/packages/frontend/core/src/blocksuite/presets/ai/utils/track.ts b/packages/frontend/core/src/blocksuite/presets/ai/utils/track.ts index 1d793829d74e3..9b0f01a826c38 100644 --- a/packages/frontend/core/src/blocksuite/presets/ai/utils/track.ts +++ b/packages/frontend/core/src/blocksuite/presets/ai/utils/track.ts @@ -2,6 +2,8 @@ import track from '@affine/track'; import type { EditorHost } from '@blocksuite/affine/block-std'; import { isInsideEdgelessEditor } from '@blocksuite/affine/blocks'; -export function getTracker(host: EditorHost) { - return track.copilot[isInsideEdgelessEditor(host) ? 'edgeless' : 'page']; +export function getTracker(host: EditorHost, inline: boolean) { + return track[isInsideEdgelessEditor(host) ? 'doc' : 'edgeless'].editor[ + inline ? 'slashMenu' : 'formatToolbar' + ]; } diff --git a/packages/frontend/track/src/events.ts b/packages/frontend/track/src/events.ts index 58f30dfd0cfaa..5222bbe496c8f 100644 --- a/packages/frontend/track/src/events.ts +++ b/packages/frontend/track/src/events.ts @@ -257,6 +257,15 @@ const PageEvents = { }, appTabsHeader: { $: ['tabAction'], + chat: [ + 'startChat', + 'abortChat', + 'resetChat', + 'addChatAttachment', + 'invokeAction', + 'discardAction', + 'acceptAction', + ], }, header: { actions: [ @@ -285,10 +294,24 @@ const PageEvents = { }, doc: { editor: { - slashMenu: ['linkDoc', 'createDoc', 'bookmark'], + slashMenu: [ + 'linkDoc', + 'createDoc', + 'bookmark', + // copilot actions + 'invokeAction', + 'discardAction', + 'acceptAction', + ], atMenu: ['linkDoc', 'import'], quickSearch: ['createDoc'], - formatToolbar: ['bold'], + formatToolbar: [ + 'bold', + // copilot actions + 'invokeAction', + 'discardAction', + 'acceptAction', + ], pageRef: ['navigate'], toolbar: ['copyBlockToLink'], }, @@ -301,24 +324,17 @@ const PageEvents = { property: ['addProperty'], }, }, - copilot: { - chat: { - $: ['startChat', 'abortChat', 'resetChat', 'addChatAttachment'], - }, - page: { - action_panel: ['invokeAction', 'discardAction', 'acceptAction'], - inline_panel: ['invokeAction', 'discardAction', 'acceptAction'], - chat: ['invokeAction', 'discardAction', 'acceptAction'], - }, - edgeless: { - action_panel: ['invokeAction', 'discardAction', 'acceptAction'], - inline_panel: ['invokeAction', 'discardAction', 'acceptAction'], - chat: ['invokeAction', 'discardAction', 'acceptAction'], + edgeless: { + editor: { + slashMenu: [ + // copilot actions + 'invokeAction', + 'discardAction', + 'acceptAction', + ], + formatToolbar: ['invokeAction', 'discardAction', 'acceptAction'], }, }, - // remove when type added - // eslint-disable-next-line @typescript-eslint/ban-types - edgeless: {}, workspace: { $: { $: ['upgradeWorkspace'],