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 62c2a29cff5e3..51f9f77dcda64 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 af5432a40eb45..0be5de02b5cf1 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 @@ -385,10 +385,6 @@ function updateEdgelessAIPanelConfig< }, }; config.discardCallback = () => { - getTracker(host).action_panel.discardAction({ - action: id, - control: 'discard_button', - }); reportResponse('result:discard'); }; config.hideCallback = () => { @@ -499,7 +495,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'); }) .catch(console.error); 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 ab9ce0cade74b..66e23288c5eb1 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 @@ -88,18 +88,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(); }, @@ -148,10 +141,6 @@ export function createInsertResp( ); }, handler: () => { - getTracker(host).action_panel.acceptAction({ - action: id, - control: 'insert', - }); reportResponse('result:insert'); handler(host, ctx); const panel = getAIPanel(host); @@ -173,10 +162,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 73feb7b7fbed8..bcf9830e49b68 100644 --- a/packages/frontend/core/src/blocksuite/presets/ai/ai-panel.ts +++ b/packages/frontend/core/src/blocksuite/presets/ai/ai-panel.ts @@ -67,10 +67,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; @@ -88,10 +84,7 @@ function asCaption( }; } -function createNewNote( - host: EditorHost, - id?: T -): AIItemConfig { +function createNewNote(host: EditorHost): AIItemConfig { return { name: 'Create new note', icon: CreateIcon, @@ -100,10 +93,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); @@ -209,10 +198,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); }, @@ -223,10 +208,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); }, @@ -237,15 +218,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), ], }, { @@ -255,10 +232,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(); @@ -268,10 +241,6 @@ export function buildTextResponseConfig< name: 'Regenerate', icon: RetryIcon, handler: () => { - getTracker(host).action_panel.invokeAction({ - action: id, - retry: true, - }); reportResponse('result:retry'); panel.generate(); }, @@ -302,10 +271,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); }, }, @@ -315,10 +281,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); }, }, @@ -328,16 +291,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), ], }, { @@ -348,10 +307,6 @@ export function buildErrorResponseConfig< icon: RetryIcon, showWhen: () => true, handler: () => { - getTracker(host).action_panel.invokeAction({ - action: id, - retry: true, - }); reportResponse('result:retry'); panel.generate(); }, @@ -387,7 +342,7 @@ export function buildErrorConfig( return { upgrade: () => { - getTracker(host).action_panel.discardAction({ + getTracker(host, false).discardAction({ action: id, control: 'paywall', }); @@ -395,7 +350,7 @@ export function buildErrorConfig( panel.hide(); }, login: () => { - getTracker(host).action_panel.discardAction({ + getTracker(host, false).discardAction({ action: id, control: 'login_required', }); @@ -403,7 +358,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 07bc4323dd49c..55068c1999768 100644 --- a/packages/frontend/track/src/events.ts +++ b/packages/frontend/track/src/events.ts @@ -249,6 +249,15 @@ const PageEvents = { }, appTabsHeader: { $: ['tabAction'], + chat: [ + 'startChat', + 'abortChat', + 'resetChat', + 'addChatAttachment', + 'invokeAction', + 'discardAction', + 'acceptAction', + ], }, header: { actions: [ @@ -275,10 +284,24 @@ const PageEvents = { }, doc: { editor: { - slashMenu: ['linkDoc', 'createDoc', 'bookmark'], + slashMenu: [ + 'linkDoc', + 'createDoc', + 'bookmark', + // copilot actions + 'invokeAction', + 'discardAction', + 'acceptAction', + ], atMenu: ['linkDoc'], quickSearch: ['createDoc'], - formatToolbar: ['bold'], + formatToolbar: [ + 'bold', + // copilot actions + 'invokeAction', + 'discardAction', + 'acceptAction', + ], pageRef: ['navigate'], toolbar: ['copyBlockToLink'], }, @@ -286,24 +309,17 @@ const PageEvents = { $: ['toggle'], }, }, - 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'],