diff --git a/packages/frontend/core/src/blocksuite/ai/chat-panel/chat-config.ts b/packages/frontend/core/src/blocksuite/ai/chat-panel/chat-config.ts index 12323c140..3fa6de845 100644 --- a/packages/frontend/core/src/blocksuite/ai/chat-panel/chat-config.ts +++ b/packages/frontend/core/src/blocksuite/ai/chat-panel/chat-config.ts @@ -34,6 +34,7 @@ export interface DocDisplayConfig { cleanup: () => void; }; getDocMeta: (docId: string) => Partial | null; + getDocPrimaryMode: (docId: string) => 'page' | 'edgeless'; getDoc: (docId: string) => Store | null; getReferenceDocs: (docIds: string[]) => { signal: Signal< diff --git a/packages/frontend/core/src/blocksuite/ai/chat-panel/chat-panel-chips.ts b/packages/frontend/core/src/blocksuite/ai/chat-panel/chat-panel-chips.ts index 3c06aa275..7d0ac2409 100644 --- a/packages/frontend/core/src/blocksuite/ai/chat-panel/chat-panel-chips.ts +++ b/packages/frontend/core/src/blocksuite/ai/chat-panel/chat-panel-chips.ts @@ -263,6 +263,7 @@ export class ChatPanelChips extends SignalWatcher( `, diff --git a/packages/frontend/core/src/blocksuite/ai/chat-panel/components/add-popover.ts b/packages/frontend/core/src/blocksuite/ai/chat-panel/components/add-popover.ts index 7077c96ca..32786e6f6 100644 --- a/packages/frontend/core/src/blocksuite/ai/chat-panel/components/add-popover.ts +++ b/packages/frontend/core/src/blocksuite/ai/chat-panel/components/add-popover.ts @@ -3,11 +3,13 @@ import type { CollectionMeta, TagMeta, } from '@affine/core/components/page-list'; +import track from '@affine/track'; import { SignalWatcher, WithDisposable } from '@blocksuite/affine/global/lit'; import { scrollbarStyle } from '@blocksuite/affine/shared/styles'; import { unsafeCSSVar, unsafeCSSVarV2 } from '@blocksuite/affine/shared/theme'; import { openFileOrFiles } from '@blocksuite/affine/shared/utils'; import { ShadowlessElement } from '@blocksuite/affine/std'; +import type { DocMeta } from '@blocksuite/affine/store'; import { CollectionsIcon, MoreHorizontalIcon, @@ -15,13 +17,12 @@ import { TagsIcon, UploadIcon, } from '@blocksuite/icons/lit'; -import type { DocMeta } from '@blocksuite/store'; import { Signal } from '@preact/signals-core'; import { css, html, type TemplateResult } from 'lit'; import { property, query, state } from 'lit/decorators.js'; import { repeat } from 'lit/directives/repeat.js'; -import type { SearchMenuConfig } from '../chat-config'; +import type { DocDisplayConfig, SearchMenuConfig } from '../chat-config'; import type { ChatChip } from '../chat-context'; enum AddPopoverMode { @@ -171,6 +172,7 @@ export class ChatPanelAddPopover extends SignalWatcher( file, state: 'processing', }); + this._track('file'); this.abortController.abort(); }; @@ -244,6 +246,9 @@ export class ChatPanelAddPopover extends SignalWatcher( @property({ attribute: false }) accessor searchMenuConfig!: SearchMenuConfig; + @property({ attribute: false }) + accessor docDisplayConfig!: DocDisplayConfig; + @property({ attribute: false }) accessor addChip!: (chip: ChatChip) => void; @@ -450,6 +455,8 @@ export class ChatPanelAddPopover extends SignalWatcher( docId: meta.id, state: 'processing', }); + const mode = this.docDisplayConfig.getDocPrimaryMode(meta.id); + this._track('doc', mode); this.abortController.abort(); }; @@ -458,6 +465,7 @@ export class ChatPanelAddPopover extends SignalWatcher( tagId: tag.id, state: 'processing', }); + this._track('tags'); this.abortController.abort(); }; @@ -466,6 +474,7 @@ export class ChatPanelAddPopover extends SignalWatcher( collectionId: collection.id, state: 'processing', }); + this._track('collections'); this.abortController.abort(); }; @@ -510,4 +519,15 @@ export class ChatPanelAddPopover extends SignalWatcher( } }); } + + private _track( + method: 'doc' | 'file' | 'tags' | 'collections', + type?: 'page' | 'edgeless' + ) { + track.$.chatPanel.chatPanelInput.addEmbeddingDoc({ + control: 'addButton', + method, + type, + }); + } } diff --git a/packages/frontend/core/src/blocksuite/ai/chat-panel/components/doc-chip.ts b/packages/frontend/core/src/blocksuite/ai/chat-panel/components/doc-chip.ts index 0337ed890..60dbecb68 100644 --- a/packages/frontend/core/src/blocksuite/ai/chat-panel/components/doc-chip.ts +++ b/packages/frontend/core/src/blocksuite/ai/chat-panel/components/doc-chip.ts @@ -1,3 +1,4 @@ +import track from '@affine/track'; import { SignalWatcher, WithDisposable } from '@blocksuite/affine/global/lit'; import { type EditorHost, ShadowlessElement } from '@blocksuite/affine/std'; import { Signal } from '@preact/signals-core'; @@ -83,6 +84,12 @@ export class ChatPanelDocChip extends SignalWatcher( ...this.chip, state: 'processing', }); + const mode = this.docDisplayConfig.getDocPrimaryMode(this.chip.docId); + track.$.chatPanel.chatPanelInput.addEmbeddingDoc({ + control: 'addButton', + method: 'suggestion', + type: mode, + }); } }; diff --git a/packages/frontend/core/src/desktop/pages/workspace/detail-page/tabs/chat.tsx b/packages/frontend/core/src/desktop/pages/workspace/detail-page/tabs/chat.tsx index c51daf4ff..ff0bda0f2 100644 --- a/packages/frontend/core/src/desktop/pages/workspace/detail-page/tabs/chat.tsx +++ b/packages/frontend/core/src/desktop/pages/workspace/detail-page/tabs/chat.tsx @@ -101,6 +101,10 @@ export const EditorChatPanel = forwardRef(function EditorChatPanel( const docRecord = docsService.list.doc$(docId).value; return docRecord?.meta$.value ?? null; }, + getDocPrimaryMode: (docId: string) => { + const docRecord = docsService.list.doc$(docId).value; + return docRecord?.primaryMode$.value ?? 'page'; + }, getDoc: (docId: string) => { const doc = workspaceService.workspace.docCollection.getDoc(docId); return doc?.getStore() ?? null; diff --git a/packages/frontend/track/src/events.ts b/packages/frontend/track/src/events.ts index 1f383f845..df0118f2e 100644 --- a/packages/frontend/track/src/events.ts +++ b/packages/frontend/track/src/events.ts @@ -132,6 +132,10 @@ type PaymentEvents = | 'confirmResumingSubscription'; // END SECTION +// SECTION: ai +type AIEvents = 'addEmbeddingDoc'; +// END SECTION + // SECTION: attachment type AttachmentEvents = | 'openAttachmentInFullscreen' @@ -177,6 +181,7 @@ type UserEvents = | AccountEvents | PaymentEvents | DNDEvents + | AIEvents | AttachmentEvents | TemplateEvents | NotificationEvents @@ -362,6 +367,9 @@ const PageEvents = { importModal: ['open'], snapshot: ['import', 'export'], }, + chatPanel: { + chatPanelInput: ['addEmbeddingDoc'], + }, attachment: { $: [ 'openAttachmentInFullscreen', @@ -567,6 +575,11 @@ export type EventArgs = { linkDoc: { type: string; journal: boolean }; drop: { type: string }; dragStart: { type: string }; + addEmbeddingDoc: { + type?: 'page' | 'edgeless'; + control: 'addButton' | 'atMenu'; + method: 'doc' | 'file' | 'tags' | 'collections' | 'suggestion'; + }; openAttachmentInFullscreen: AttachmentEventArgs; openAttachmentInNewTab: AttachmentEventArgs; openAttachmentInPeekView: AttachmentEventArgs;