There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.
TypeScript appcrdteditorelectronknowledge-basemarkdownmironotesnotionnotion-alternativerustrust-langrust-languagetabletableviewwhiteboardwikiworkspace
feat(core): add chat-panel track (#11323)
akumatusafd1a30b96fc
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.tsindex 12323c1402..3fa6de8455 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<DocMeta> | 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.tsindex 3c06aa275d..7d0ac24099 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(<chat-panel-add-popover.addChip=${this._addChip}.searchMenuConfig=${this.searchMenuConfig}+ .docDisplayConfig=${this.docDisplayConfig}.abortController=${this._abortController}></chat-panel-add-popover>`,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.tsindex 7077c96ca0..32786e6f6a 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.tsindex 0337ed8902..60dbecb686 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.tsxindex c51daf4ffb..ff0bda0f20 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.tsindex 1f383f8450..df0118f2e8 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: attachmenttype 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;