Skip to content

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.

refactor: move ai-item components to frontend core (#10369)

Saul-Mironef8cabe8bb10b
diff --git a/blocksuite/affine/components/package.json b/blocksuite/affine/components/package.json
index f0a7d643ec..ca73cc42f0 100644
--- a/blocksuite/affine/components/package.json
+++ b/blocksuite/affine/components/package.json
@@ -40,7 +40,6 @@
},
"exports": {
".": "./src/index.ts",
- "./ai-item": "./src/ai-item/index.ts",
"./color-picker": "./src/color-picker/index.ts",
"./icons": "./src/icons/index.ts",
"./peek": "./src/peek/index.ts",
diff --git a/blocksuite/blocks/src/effects.ts b/blocksuite/blocks/src/effects.ts
index 6b70844b68..a89928570f 100644
--- a/blocksuite/blocks/src/effects.ts
+++ b/blocksuite/blocks/src/effects.ts
@@ -16,7 +16,6 @@ import { effects as blockRootEffects } from '@blocksuite/affine-block-root/effec
import { effects as blockSurfaceEffects } from '@blocksuite/affine-block-surface/effects';
import { effects as blockSurfaceRefEffects } from '@blocksuite/affine-block-surface-ref/effects';
import { effects as blockTableEffects } from '@blocksuite/affine-block-table/effects';
-import { effects as componentAiItemEffects } from '@blocksuite/affine-components/ai-item';
import { BlockSelection } from '@blocksuite/affine-components/block-selection';
import { BlockZeroWidth } from '@blocksuite/affine-components/block-zero-width';
import { effects as componentCaptionEffects } from '@blocksuite/affine-components/caption';
@@ -82,7 +81,6 @@ export function effects() {
componentToolbarEffects();
componentDropIndicatorEffects();
componentToggleButtonEffects();
- componentAiItemEffects();
componentColorPickerEffects();
componentEmbedCardModalEffects();
componentDocTitleEffects();
diff --git a/blocksuite/blocks/src/index.ts b/blocksuite/blocks/src/index.ts
index 19a6294ce4..83b5808068 100644
--- a/blocksuite/blocks/src/index.ts
+++ b/blocksuite/blocks/src/index.ts
@@ -19,17 +19,6 @@ export * from '@blocksuite/affine-block-root';
export * from '@blocksuite/affine-block-surface';
export * from '@blocksuite/affine-block-surface-ref';
export * from '@blocksuite/affine-block-table';
-export {
- type AIError,
- AIErrorType,
- type AIItemConfig,
- type AIItemGroupConfig,
- AIItemList,
- type AISubItemConfig,
- GeneralNetworkError,
- PaymentRequiredError,
- UnauthorizedError,
-} from '@blocksuite/affine-components/ai-item';
export {
menu,
type MenuOptions,
diff --git a/blocksuite/affine/components/src/ai-item/ai-item-list.ts b/packages/frontend/core/src/blocksuite/presets/ai/_common/components/ai-item/ai-item-list.ts
similarity index 96%
rename from blocksuite/affine/components/src/ai-item/ai-item-list.ts
rename to packages/frontend/core/src/blocksuite/presets/ai/_common/components/ai-item/ai-item-list.ts
index b667198179..a95db5cb72 100644
--- a/blocksuite/affine/components/src/ai-item/ai-item-list.ts
+++ b/packages/frontend/core/src/blocksuite/presets/ai/_common/components/ai-item/ai-item-list.ts
@@ -2,15 +2,15 @@ import {
EditorHost,
PropTypes,
requiredProperties,
-} from '@blocksuite/block-std';
-import { WithDisposable } from '@blocksuite/global/utils';
+} from '@blocksuite/affine/block-std';
+import { createLitPortal } from '@blocksuite/affine/blocks';
+import { WithDisposable } from '@blocksuite/affine/global/utils';
import { flip, offset } from '@floating-ui/dom';
import { baseTheme } from '@toeverything/theme';
import { css, html, LitElement, nothing, unsafeCSS } from 'lit';
import { property } from 'lit/decorators.js';
import { repeat } from 'lit/directives/repeat.js';
-import { createLitPortal } from '../portal';
import type { AIItem } from './ai-item';
import { SUBMENU_OFFSET_CROSS_AXIS, SUBMENU_OFFSET_MAIN_AXIS } from './const';
import type { AIItemConfig, AIItemGroupConfig } from './types';
diff --git a/blocksuite/affine/components/src/ai-item/ai-item.ts b/packages/frontend/core/src/blocksuite/presets/ai/_common/components/ai-item/ai-item.ts
similarity index 90%
rename from blocksuite/affine/components/src/ai-item/ai-item.ts
rename to packages/frontend/core/src/blocksuite/presets/ai/_common/components/ai-item/ai-item.ts
index db65b927e2..eb8eb7e63a 100644
--- a/blocksuite/affine/components/src/ai-item/ai-item.ts
+++ b/packages/frontend/core/src/blocksuite/presets/ai/_common/components/ai-item/ai-item.ts
@@ -2,12 +2,12 @@ import {
EditorHost,
PropTypes,
requiredProperties,
-} from '@blocksuite/block-std';
-import { WithDisposable } from '@blocksuite/global/utils';
+} from '@blocksuite/affine/block-std';
+import { ArrowRightIcon, EnterIcon } from '@blocksuite/affine/blocks';
+import { WithDisposable } from '@blocksuite/affine/global/utils';
import { css, html, LitElement, nothing } from 'lit';
import { property, query } from 'lit/decorators.js';
-import { ArrowRightIcon, EnterIcon } from '../icons';
import { menuItemStyles } from './styles';
import type { AIItemConfig } from './types';
diff --git a/blocksuite/affine/components/src/ai-item/ai-sub-item-list.ts b/packages/frontend/core/src/blocksuite/presets/ai/_common/components/ai-item/ai-sub-item-list.ts
similarity index 93%
rename from blocksuite/affine/components/src/ai-item/ai-sub-item-list.ts
rename to packages/frontend/core/src/blocksuite/presets/ai/_common/components/ai-item/ai-sub-item-list.ts
index 4a72db8cf2..487969929e 100644
--- a/blocksuite/affine/components/src/ai-item/ai-sub-item-list.ts
+++ b/packages/frontend/core/src/blocksuite/presets/ai/_common/components/ai-item/ai-sub-item-list.ts
@@ -2,13 +2,13 @@ import {
EditorHost,
PropTypes,
requiredProperties,
-} from '@blocksuite/block-std';
-import { WithDisposable } from '@blocksuite/global/utils';
+} from '@blocksuite/affine/block-std';
+import { EnterIcon } from '@blocksuite/affine/blocks';
+import { WithDisposable } from '@blocksuite/affine/global/utils';
import { baseTheme } from '@toeverything/theme';
import { css, html, LitElement, nothing, unsafeCSS } from 'lit';
import { property } from 'lit/decorators.js';
-import { EnterIcon } from '../icons';
import { menuItemStyles } from './styles';
import type { AIItemConfig, AISubItemConfig } from './types';
diff --git a/blocksuite/affine/components/src/ai-item/const.ts b/packages/frontend/core/src/blocksuite/presets/ai/_common/components/ai-item/const.ts
similarity index 100%
rename from blocksuite/affine/components/src/ai-item/const.ts
rename to packages/frontend/core/src/blocksuite/presets/ai/_common/components/ai-item/const.ts
diff --git a/blocksuite/affine/components/src/ai-item/index.ts b/packages/frontend/core/src/blocksuite/presets/ai/_common/components/ai-item/index.ts
similarity index 100%
rename from blocksuite/affine/components/src/ai-item/index.ts
rename to packages/frontend/core/src/blocksuite/presets/ai/_common/components/ai-item/index.ts
diff --git a/blocksuite/affine/components/src/ai-item/styles.ts b/packages/frontend/core/src/blocksuite/presets/ai/_common/components/ai-item/styles.ts
similarity index 100%
rename from blocksuite/affine/components/src/ai-item/styles.ts
rename to packages/frontend/core/src/blocksuite/presets/ai/_common/components/ai-item/styles.ts
diff --git a/blocksuite/affine/components/src/ai-item/types.ts b/packages/frontend/core/src/blocksuite/presets/ai/_common/components/ai-item/types.ts
similarity index 90%
rename from blocksuite/affine/components/src/ai-item/types.ts
rename to packages/frontend/core/src/blocksuite/presets/ai/_common/components/ai-item/types.ts
index 151ca21efc..237b56814c 100644
--- a/blocksuite/affine/components/src/ai-item/types.ts
+++ b/packages/frontend/core/src/blocksuite/presets/ai/_common/components/ai-item/types.ts
@@ -1,5 +1,9 @@
-import type { DocMode } from '@blocksuite/affine-model';
-import type { Chain, EditorHost, InitCommandCtx } from '@blocksuite/block-std';
+import type {
+ Chain,
+ EditorHost,
+ InitCommandCtx,
+} from '@blocksuite/affine/block-std';
+import type { DocMode } from '@blocksuite/affine/blocks';
import type { TemplateResult } from 'lit';
export interface AIItemGroupConfig {
diff --git a/packages/frontend/core/src/blocksuite/presets/ai/_common/components/ask-ai-button.ts b/packages/frontend/core/src/blocksuite/presets/ai/_common/components/ask-ai-button.ts
index 4cec93f1fd..f4a6964a72 100644
--- a/packages/frontend/core/src/blocksuite/presets/ai/_common/components/ask-ai-button.ts
+++ b/packages/frontend/core/src/blocksuite/presets/ai/_common/components/ask-ai-button.ts
@@ -1,11 +1,7 @@
import './ask-ai-panel';
import { type EditorHost } from '@blocksuite/affine/block-std';
-import {
- type AIItemGroupConfig,
- createLitPortal,
- HoverController,
-} from '@blocksuite/affine/blocks';
+import { createLitPortal, HoverController } from '@blocksuite/affine/blocks';
import { WithDisposable } from '@blocksuite/affine/global/utils';
import { flip, offset } from '@floating-ui/dom';
import { css, html, LitElement, nothing } from 'lit';
@@ -13,6 +9,7 @@ import { property, query } from 'lit/decorators.js';
import { ref } from 'lit/directives/ref.js';
import { styleMap } from 'lit/directives/style-map.js';
+import type { AIItemGroupConfig } from './ai-item/types';
import type { ButtonSize } from './ask-ai-icon';
type toggleType = 'hover' | 'click';
diff --git a/packages/frontend/core/src/blocksuite/presets/ai/_common/components/ask-ai-panel.ts b/packages/frontend/core/src/blocksuite/presets/ai/_common/components/ask-ai-panel.ts
index a8fb411082..33ef20e6a1 100644
--- a/packages/frontend/core/src/blocksuite/presets/ai/_common/components/ask-ai-panel.ts
+++ b/packages/frontend/core/src/blocksuite/presets/ai/_common/components/ask-ai-panel.ts
@@ -1,15 +1,13 @@
import { type EditorHost } from '@blocksuite/affine/block-std';
-import {
- type AIItemGroupConfig,
- DocModeProvider,
- scrollbarStyle,
-} from '@blocksuite/affine/blocks';
+import { DocModeProvider, scrollbarStyle } from '@blocksuite/affine/blocks';
import { WithDisposable } from '@blocksuite/affine/global/utils';
import { cssVar } from '@toeverything/theme';
import { css, html, LitElement, unsafeCSS } from 'lit';
import { property } from 'lit/decorators.js';
import { styleMap } from 'lit/directives/style-map.js';
+import type { AIItemGroupConfig } from './ai-item/types';
+
export class AskAIPanel extends WithDisposable(LitElement) {
static override styles = css`
:host {
diff --git a/packages/frontend/core/src/blocksuite/presets/ai/_common/components/ask-ai-toolbar.ts b/packages/frontend/core/src/blocksuite/presets/ai/_common/components/ask-ai-toolbar.ts
index 607fc1952d..b535dc929f 100644
--- a/packages/frontend/core/src/blocksuite/presets/ai/_common/components/ask-ai-toolbar.ts
+++ b/packages/frontend/core/src/blocksuite/presets/ai/_common/components/ask-ai-toolbar.ts
@@ -3,10 +3,7 @@ import {
type EditorHost,
TextSelection,
} from '@blocksuite/affine/block-std';
-import {
- type AIItemGroupConfig,
- createLitPortal,
-} from '@blocksuite/affine/blocks';
+import { createLitPortal } from '@blocksuite/affine/blocks';
import { WithDisposable } from '@blocksuite/affine/global/utils';
import { flip, offset } from '@floating-ui/dom';
import { css, html, LitElement } from 'lit';
@@ -16,6 +13,7 @@ import { AIProvider } from '../../provider';
import { getAIPanelWidget } from '../../utils/ai-widgets';
import { extractSelectedContent } from '../../utils/extract';
import type { AffineAIPanelWidgetConfig } from '../../widgets/ai-panel/type';
+import type { AIItemGroupConfig } from './ai-item/types';
export class AskAIToolbarButton extends WithDisposable(LitElement) {
static override styles = css`
diff --git a/packages/frontend/core/src/blocksuite/presets/ai/_common/config.ts b/packages/frontend/core/src/blocksuite/presets/ai/_common/config.ts
index adb83c93e4..f718299fb3 100644
--- a/packages/frontend/core/src/blocksuite/presets/ai/_common/config.ts
+++ b/packages/frontend/core/src/blocksuite/presets/ai/_common/config.ts
@@ -1,7 +1,5 @@
import type { Chain, InitCommandCtx } from '@blocksuite/affine/block-std';
import {
- type AIItemGroupConfig,
- type AISubItemConfig,
CodeBlockModel,
getSelectedModelsCommand,
ImageBlockModel,
@@ -19,6 +17,10 @@ import {
} from '../actions/types';
import { AIProvider } from '../provider';
import { getAIPanelWidget } from '../utils/ai-widgets';
+import type {
+ AIItemGroupConfig,
+ AISubItemConfig,
+} from './components/ai-item/types';
import {
AIDoneIcon,
AIImageIcon,
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 12487c73b5..e9e8a5097e 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
@@ -1,7 +1,5 @@
import { type EditorHost, TextSelection } from '@blocksuite/affine/block-std';
import {
- type AIError,
- type AIItemGroupConfig,
AIStarIconWithAnimation,
createLitPortal,
} from '@blocksuite/affine/blocks';
@@ -9,6 +7,10 @@ import { assertExists } from '@blocksuite/affine/global/utils';
import { flip, offset } from '@floating-ui/dom';
import { html, type TemplateResult } from 'lit';
+import type {
+ AIError,
+ AIItemGroupConfig,
+} from '../_common/components/ai-item/types';
import {
buildCopyConfig,
buildErrorConfig,
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 49bf0612ff..79fbd450b4 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
@@ -3,7 +3,6 @@ import {
GfxControllerIdentifier,
type GfxModel,
} from '@blocksuite/affine/block-std/gfx';
-import type { AIError } from '@blocksuite/affine/blocks';
import {
CodeBlockModel,
EdgelessTextBlockModel,
@@ -21,6 +20,7 @@ import type { TemplateResult } from 'lit';
import { AIChatBlockModel } from '../../../blocks';
import { getContentFromSlice } from '../../_common';
+import type { AIError } from '../_common/components/ai-item/types';
import { AIProvider } from '../provider';
import { reportResponse } from '../utils/action-reporter';
import { getAIPanelWidget } from '../utils/ai-widgets';
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 0b3265ddba..f6ea826465 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
@@ -1,7 +1,6 @@
import type { EditorHost } from '@blocksuite/affine/block-std';
import { GfxControllerIdentifier } from '@blocksuite/affine/block-std/gfx';
import type {
- AIItemConfig,
EdgelessElementToolbarWidget,
MindmapElementModel,
ShapeElementModel,
@@ -28,6 +27,7 @@ import { html, type TemplateResult } from 'lit';
import { styleMap } from 'lit/directives/style-map.js';
import { insertFromMarkdown } from '../../_common';
+import type { AIItemConfig } from '../_common/components/ai-item/types';
import { AIPenIcon, ChatWithAIIcon } from '../_common/icons';
import { AIProvider } from '../provider';
import { reportResponse } from '../utils/action-reporter';
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 5df1cb6e3c..c7ef5a61f5 100644
--- a/packages/frontend/core/src/blocksuite/presets/ai/ai-panel.ts
+++ b/packages/frontend/core/src/blocksuite/presets/ai/ai-panel.ts
@@ -2,7 +2,6 @@ import { AINetworkSearchService } from '@affine/core/modules/ai-button/services/
import type { EditorHost } from '@blocksuite/affine/block-std';
import { GfxControllerIdentifier } from '@blocksuite/affine/block-std/gfx';
import {
- type AIItemConfig,
ImageBlockModel,
isInsideEdgelessEditor,
matchModels,
@@ -14,6 +13,7 @@ import type { FrameworkProvider } from '@toeverything/infra';
import type { TemplateResult } from 'lit';
import { createTextRenderer, insertFromMarkdown } from '../_common';
+import type { AIItemConfig } from './_common/components/ai-item/types';
import {
AIPenIcon,
AIStarIconWithAnimation,
diff --git a/packages/frontend/core/src/blocksuite/presets/ai/chat-panel/chat-context.ts b/packages/frontend/core/src/blocksuite/presets/ai/chat-panel/chat-context.ts
index e1c077c8e7..449990dfc0 100644
--- a/packages/frontend/core/src/blocksuite/presets/ai/chat-panel/chat-context.ts
+++ b/packages/frontend/core/src/blocksuite/presets/ai/chat-panel/chat-context.ts
@@ -1,6 +1,7 @@
-import type { AIError } from '@blocksuite/affine/blocks';
import type { Signal } from '@preact/signals-core';
+import type { AIError } from '../_common/components/ai-item/types';
+
export type ChatMessage = {
id: string;
content: string;
diff --git a/packages/frontend/core/src/blocksuite/presets/ai/chat-panel/chat-panel-input.ts b/packages/frontend/core/src/blocksuite/presets/ai/chat-panel/chat-panel-input.ts
index b668096917..d8256ae41b 100644
--- a/packages/frontend/core/src/blocksuite/presets/ai/chat-panel/chat-panel-input.ts
+++ b/packages/frontend/core/src/blocksuite/presets/ai/chat-panel/chat-panel-input.ts
@@ -1,16 +1,13 @@
import { stopPropagation } from '@affine/core/utils';
import type { EditorHost } from '@blocksuite/affine/block-std';
-import {
- type AIError,
- openFileOrFiles,
- unsafeCSSVarV2,
-} from '@blocksuite/affine/blocks';
+import { openFileOrFiles, unsafeCSSVarV2 } from '@blocksuite/affine/blocks';
import { SignalWatcher, WithDisposable } from '@blocksuite/affine/global/utils';
import { ImageIcon, PublishIcon } from '@blocksuite/icons/lit';
import { css, html, LitElement, nothing } from 'lit';
import { property, query, state } from 'lit/decorators.js';
import { repeat } from 'lit/directives/repeat.js';
+import type { AIError } from '../_common/components/ai-item/types';
import {
ChatAbortIcon,
ChatClearIcon,
diff --git a/packages/frontend/core/src/blocksuite/presets/ai/chat-panel/chat-panel-messages.ts b/packages/frontend/core/src/blocksuite/presets/ai/chat-panel/chat-panel-messages.ts
index a18c9d2acb..9690206dea 100644
--- a/packages/frontend/core/src/blocksuite/presets/ai/chat-panel/chat-panel-messages.ts
+++ b/packages/frontend/core/src/blocksuite/presets/ai/chat-panel/chat-panel-messages.ts
@@ -1,13 +1,10 @@
import type { EditorHost } from '@blocksuite/affine/block-std';
import { ShadowlessElement } from '@blocksuite/affine/block-std';
import {
- type AIError,
DocModeProvider,
FeatureFlagService,
isInsidePageEditor,
- PaymentRequiredError,
type SpecBuilder,
- UnauthorizedError,
} from '@blocksuite/affine/blocks';
import { WithDisposable } from '@blocksuite/affine/global/utils';
import type { BaseSelection } from '@blocksuite/affine/store';
@@ -21,6 +18,11 @@ import {
EdgelessEditorActions,
PageEditorActions,
} from '../_common/chat-actions-handle';
+import {
+ type AIError,
+ PaymentRequiredError,
+ UnauthorizedError,
+} from '../_common/components/ai-item/types';
import { AffineAvatarIcon, AffineIcon, DownArrowIcon } from '../_common/icons';
import { AIChatErrorRenderer } from '../messages/error';
import { AIProvider } from '../provider';
diff --git a/packages/frontend/core/src/blocksuite/presets/ai/entries/edgeless/actions-config.ts b/packages/frontend/core/src/blocksuite/presets/ai/entries/edgeless/actions-config.ts
index 9f0cb59a4d..38e6fa140b 100644
--- a/packages/frontend/core/src/blocksuite/presets/ai/entries/edgeless/actions-config.ts
+++ b/packages/frontend/core/src/blocksuite/presets/ai/entries/edgeless/actions-config.ts
@@ -1,5 +1,4 @@
import {
- type AIItemGroupConfig,
AIStarIconWithAnimation,
MindmapElementModel,
ShapeElementModel,
@@ -7,6 +6,7 @@ import {
TextElementModel,
} from '@blocksuite/affine/blocks';
+import type { AIItemGroupConfig } from '../../_common/components/ai-item/types';
import {
AIExpandMindMapIcon,
AIImageIcon,
diff --git a/packages/frontend/core/src/blocksuite/presets/ai/entries/edgeless/index.ts b/packages/frontend/core/src/blocksuite/presets/ai/entries/edgeless/index.ts
index 84604418be..d4ccc9953d 100644
--- a/packages/frontend/core/src/blocksuite/presets/ai/entries/edgeless/index.ts
+++ b/packages/frontend/core/src/blocksuite/presets/ai/entries/edgeless/index.ts
@@ -1,5 +1,4 @@
import type {
- AIItemGroupConfig,
DocMode,
EdgelessElementToolbarWidget,
EdgelessRootBlockComponent,
@@ -7,6 +6,7 @@ import type {
import { noop } from '@blocksuite/affine/global/utils';
import { html } from 'lit';
+import type { AIItemGroupConfig } from '../../_common/components/ai-item/types';
import { AIProvider } from '../../provider';
import { getAIPanelWidget } from '../../utils/ai-widgets';
import { getEdgelessCopilotWidget } from '../../utils/edgeless';
diff --git a/packages/frontend/core/src/blocksuite/presets/ai/entries/slash-menu/setup-slash-menu.ts b/packages/frontend/core/src/blocksuite/presets/ai/entries/slash-menu/setup-slash-menu.ts
index d68a64a837..0788969298 100644
--- a/packages/frontend/core/src/blocksuite/presets/ai/entries/slash-menu/setup-slash-menu.ts
+++ b/packages/frontend/core/src/blocksuite/presets/ai/entries/slash-menu/setup-slash-menu.ts
@@ -4,7 +4,6 @@ import {
type AffineSlashMenuItem,
AffineSlashMenuWidget,
type AffineSlashSubMenu,
- type AIItemConfig,
AIStarIcon,
DocModeProvider,
} from '@blocksuite/affine/blocks';
@@ -12,6 +11,7 @@ import { assertExists } from '@blocksuite/affine/global/utils';
import { MoreHorizontalIcon } from '@blocksuite/icons/lit';
import { html } from 'lit';
+import type { AIItemConfig } from '../../_common/components/ai-item/types';
import { pageAIGroups } from '../../_common/config';
import { handleInlineAskAIAction } from '../../actions/doc-handler';
import { AIProvider } from '../../provider';
diff --git a/packages/frontend/core/src/blocksuite/presets/ai/messages/error.ts b/packages/frontend/core/src/blocksuite/presets/ai/messages/error.ts
index 00c51ee996..3f5753fa65 100644
--- a/packages/frontend/core/src/blocksuite/presets/ai/messages/error.ts
+++ b/packages/frontend/core/src/blocksuite/presets/ai/messages/error.ts
@@ -1,11 +1,5 @@
import { type EditorHost } from '@blocksuite/affine/block-std';
-import {
- type AIError,
- PaymentRequiredError,
- scrollbarStyle,
- UnauthorizedError,
- unsafeCSSVarV2,
-} from '@blocksuite/affine/blocks';
+import { scrollbarStyle, unsafeCSSVarV2 } from '@blocksuite/affine/blocks';
import { SignalWatcher, WithDisposable } from '@blocksuite/affine/global/utils';
import { ToggleDownIcon } from '@blocksuite/icons/lit';
import { signal } from '@preact/signals-core';
@@ -13,6 +7,11 @@ import { baseTheme } from '@toeverything/theme';
import { css, html, LitElement, nothing, unsafeCSS } from 'lit';
import { property } from 'lit/decorators.js';
+import {
+ type AIError,
+ PaymentRequiredError,
+ UnauthorizedError,
+} from '../_common/components/ai-item/types';
import { ErrorTipIcon } from '../_common/icons';
import { AIProvider } from '../provider';
diff --git a/packages/frontend/core/src/blocksuite/presets/ai/peek-view/chat-block-input.ts b/packages/frontend/core/src/blocksuite/presets/ai/peek-view/chat-block-input.ts
index 62d686c815..2869604f8c 100644
--- a/packages/frontend/core/src/blocksuite/presets/ai/peek-view/chat-block-input.ts
+++ b/packages/frontend/core/src/blocksuite/presets/ai/peek-view/chat-block-input.ts
@@ -1,9 +1,5 @@
import type { EditorHost } from '@blocksuite/affine/block-std';
-import {
- type AIError,
- openFileOrFiles,
- unsafeCSSVarV2,
-} from '@blocksuite/affine/blocks';
+import { openFileOrFiles, unsafeCSSVarV2 } from '@blocksuite/affine/blocks';
import { SignalWatcher } from '@blocksuite/affine/global/utils';
import { ImageIcon, PublishIcon } from '@blocksuite/icons/lit';
import { css, html, LitElement, nothing } from 'lit';
@@ -11,6 +7,7 @@ import { property, query, state } from 'lit/decorators.js';
import { classMap } from 'lit/directives/class-map.js';
import type { ChatMessage } from '../../../blocks';
+import type { AIError } from '../_common/components/ai-item/types';
import { ChatAbortIcon, ChatClearIcon, ChatSendIcon } from '../_common/icons';
import type { AINetworkSearchConfig } from '../chat-panel/chat-config';
import {
diff --git a/packages/frontend/core/src/blocksuite/presets/ai/peek-view/chat-block-peek-view.ts b/packages/frontend/core/src/blocksuite/presets/ai/peek-view/chat-block-peek-view.ts
index 89b18a7fc1..b8981b3d60 100644
--- a/packages/frontend/core/src/blocksuite/presets/ai/peek-view/chat-block-peek-view.ts
+++ b/packages/frontend/core/src/blocksuite/presets/ai/peek-view/chat-block-peek-view.ts
@@ -1,6 +1,5 @@
-import { type EditorHost } from '@blocksuite/affine/block-std';
+import type { EditorHost } from '@blocksuite/affine/block-std';
import {
- type AIError,
CanvasElementType,
ConnectorMode,
DocModeProvider,
@@ -26,6 +25,7 @@ import {
constructUserInfoWithMessages,
queryHistoryMessages,
} from '../_common/chat-actions-handle';
+import type { AIError } from '../_common/components/ai-item/types';
import { SmallHintIcon } from '../_common/icons';
import type { AINetworkSearchConfig } from '../chat-panel/chat-config';
import { AIChatErrorRenderer } from '../messages/error';
diff --git a/packages/frontend/core/src/blocksuite/presets/ai/peek-view/types.ts b/packages/frontend/core/src/blocksuite/presets/ai/peek-view/types.ts
index f6ef26edcc..46ff6f0196 100644
--- a/packages/frontend/core/src/blocksuite/presets/ai/peek-view/types.ts
+++ b/packages/frontend/core/src/blocksuite/presets/ai/peek-view/types.ts
@@ -1,6 +1,5 @@
-import type { AIError } from '@blocksuite/affine/blocks';
-
import type { ChatMessage } from '../../../blocks';
+import type { AIError } from '../_common/components/ai-item/types';
export type ChatStatus =
| 'success'
diff --git a/packages/frontend/core/src/blocksuite/presets/ai/provider.ts b/packages/frontend/core/src/blocksuite/presets/ai/provider.ts
index 20aedd1973..10be2cbb4c 100644
--- a/packages/frontend/core/src/blocksuite/presets/ai/provider.ts
+++ b/packages/frontend/core/src/blocksuite/presets/ai/provider.ts
@@ -1,11 +1,11 @@
import type { EditorHost } from '@blocksuite/affine/block-std';
-import {
- PaymentRequiredError,
- UnauthorizedError,
-} from '@blocksuite/affine/blocks';
import { Slot } from '@blocksuite/affine/global/utils';
import { captureException } from '@sentry/react';
+import {
+ PaymentRequiredError,
+ UnauthorizedError,
+} from './_common/components/ai-item/types';
import type { ChatContextValue } from './chat-panel/chat-context';
export interface AIUserInfo {
diff --git a/packages/frontend/core/src/blocksuite/presets/ai/widgets/ai-panel/ai-panel.ts b/packages/frontend/core/src/blocksuite/presets/ai/widgets/ai-panel/ai-panel.ts
index 16905365be..b6c0e85007 100644
--- a/packages/frontend/core/src/blocksuite/presets/ai/widgets/ai-panel/ai-panel.ts
+++ b/packages/frontend/core/src/blocksuite/presets/ai/widgets/ai-panel/ai-panel.ts
@@ -4,7 +4,6 @@ import {
AFFINE_FORMAT_BAR_WIDGET,
AFFINE_VIEWPORT_OVERLAY_WIDGET,
type AffineViewportOverlayWidget,
- type AIError,
DocModeProvider,
getPageRootByElement,
NotificationProvider,
@@ -27,6 +26,7 @@ import { css, html, nothing, type PropertyValues } from 'lit';
import { property, query } from 'lit/decorators.js';
import { choose } from 'lit/directives/choose.js';
+import type { AIError } from '../../_common/components/ai-item/types.js';
import type { AIPanelGenerating } from './components/index.js';
import type { AffineAIPanelState, AffineAIPanelWidgetConfig } from './type.js';
diff --git a/packages/frontend/core/src/blocksuite/presets/ai/widgets/ai-panel/components/state/error.ts b/packages/frontend/core/src/blocksuite/presets/ai/widgets/ai-panel/components/state/error.ts
index 541b89bbe1..21130eeabe 100644
--- a/packages/frontend/core/src/blocksuite/presets/ai/widgets/ai-panel/components/state/error.ts
+++ b/packages/frontend/core/src/blocksuite/presets/ai/widgets/ai-panel/components/state/error.ts
@@ -1,11 +1,14 @@
import type { EditorHost } from '@blocksuite/affine/block-std';
-import { AIErrorType, type AIItemGroupConfig } from '@blocksuite/affine/blocks';
import { WithDisposable } from '@blocksuite/affine/global/utils';
import { baseTheme } from '@toeverything/theme';
import { css, html, LitElement, nothing, unsafeCSS } from 'lit';
import { property } from 'lit/decorators.js';
import { choose } from 'lit/directives/choose.js';
+import {
+ AIErrorType,
+ type AIItemGroupConfig,
+} from '../../../../_common/components/ai-item/types.js';
import type { AIPanelErrorConfig, CopyConfig } from '../../type.js';
import { filterAIItemGroup } from '../../utils.js';
diff --git a/packages/frontend/core/src/blocksuite/presets/ai/widgets/ai-panel/type.ts b/packages/frontend/core/src/blocksuite/presets/ai/widgets/ai-panel/type.ts
index 5a8b5e3589..a954fd4eac 100644
--- a/packages/frontend/core/src/blocksuite/presets/ai/widgets/ai-panel/type.ts
+++ b/packages/frontend/core/src/blocksuite/presets/ai/widgets/ai-panel/type.ts
@@ -1,7 +1,11 @@
-import type { AIError, AIItemGroupConfig } from '@blocksuite/affine/blocks';
import type { Signal } from '@preact/signals-core';
import type { nothing, TemplateResult } from 'lit';
+import type {
+ AIError,
+ AIItemGroupConfig,
+} from '../../_common/components/ai-item/types';
+
export interface CopyConfig {
allowed: boolean;
onCopy: () => boolean | Promise<boolean>;
diff --git a/packages/frontend/core/src/blocksuite/presets/ai/widgets/ai-panel/utils.ts b/packages/frontend/core/src/blocksuite/presets/ai/widgets/ai-panel/utils.ts
index 1f0adf4792..99b343136c 100644
--- a/packages/frontend/core/src/blocksuite/presets/ai/widgets/ai-panel/utils.ts
+++ b/packages/frontend/core/src/blocksuite/presets/ai/widgets/ai-panel/utils.ts
@@ -1,7 +1,8 @@
import type { EditorHost } from '@blocksuite/affine/block-std';
-import type { AIItemGroupConfig } from '@blocksuite/affine/blocks';
import { isInsidePageEditor } from '@blocksuite/affine/blocks';
+import type { AIItemGroupConfig } from '../../_common/components/ai-item/types';
+
export function filterAIItemGroup(
host: EditorHost,
configs: AIItemGroupConfig[]
diff --git a/packages/frontend/core/src/blocksuite/presets/ai/widgets/edgeless-copilot-panel/index.ts b/packages/frontend/core/src/blocksuite/presets/ai/widgets/edgeless-copilot-panel/index.ts
index 2e601335e7..756c92ee36 100644
--- a/packages/frontend/core/src/blocksuite/presets/ai/widgets/edgeless-copilot-panel/index.ts
+++ b/packages/frontend/core/src/blocksuite/presets/ai/widgets/edgeless-copilot-panel/index.ts
@@ -1,10 +1,11 @@
import type { EditorHost } from '@blocksuite/affine/block-std';
-import type { AIItemGroupConfig } from '@blocksuite/affine/blocks';
import { on, scrollbarStyle, stopPropagation } from '@blocksuite/affine/blocks';
import { WithDisposable } from '@blocksuite/affine/global/utils';
import { css, html, LitElement, nothing } from 'lit';
import { property } from 'lit/decorators.js';
+import type { AIItemGroupConfig } from '../../_common/components/ai-item/types';
+
export class EdgelessCopilotPanel extends WithDisposable(LitElement) {
static override styles = css`
:host {
diff --git a/packages/frontend/core/src/blocksuite/presets/ai/widgets/edgeless-copilot-panel/toolbar-entry.ts b/packages/frontend/core/src/blocksuite/presets/ai/widgets/edgeless-copilot-panel/toolbar-entry.ts
index 832760e639..b80323a7b9 100644
--- a/packages/frontend/core/src/blocksuite/presets/ai/widgets/edgeless-copilot-panel/toolbar-entry.ts
+++ b/packages/frontend/core/src/blocksuite/presets/ai/widgets/edgeless-copilot-panel/toolbar-entry.ts
@@ -3,12 +3,12 @@ import {
GfxControllerIdentifier,
isGfxGroupCompatibleModel,
} from '@blocksuite/affine/block-std/gfx';
-import type { AIItemGroupConfig } from '@blocksuite/affine/blocks';
import { AIStarIcon, sortEdgelessElements } from '@blocksuite/affine/blocks';
import { WithDisposable } from '@blocksuite/affine/global/utils';
import { css, html, LitElement } from 'lit';
import { property } from 'lit/decorators.js';
+import type { AIItemGroupConfig } from '../../_common/components/ai-item/types';
import type { CopilotTool } from '../../tool/copilot-tool';
export class EdgelessCopilotToolbarEntry extends WithDisposable(LitElement) {
diff --git a/packages/frontend/core/src/blocksuite/presets/ai/widgets/edgeless-copilot/index.ts b/packages/frontend/core/src/blocksuite/presets/ai/widgets/edgeless-copilot/index.ts
index c769598434..b1e2d11fcd 100644
--- a/packages/frontend/core/src/blocksuite/presets/ai/widgets/edgeless-copilot/index.ts
+++ b/packages/frontend/core/src/blocksuite/presets/ai/widgets/edgeless-copilot/index.ts
@@ -1,9 +1,6 @@
import { WidgetComponent } from '@blocksuite/affine/block-std';
import { GfxControllerIdentifier } from '@blocksuite/affine/block-std/gfx';
-import type {
- AIItemGroupConfig,
- RootBlockModel,
-} from '@blocksuite/affine/blocks';
+import type { RootBlockModel } from '@blocksuite/affine/blocks';
import {
EdgelessLegacySlotIdentifier,
MOUSE_BUTTON,
@@ -26,6 +23,7 @@ import { css, html, nothing } from 'lit';
import { query, state } from 'lit/decorators.js';
import { styleMap } from 'lit/directives/style-map.js';
+import type { AIItemGroupConfig } from '../../_common/components/ai-item/types.js';
import {
AFFINE_AI_PANEL_WIDGET,
AffineAIPanelWidget,
diff --git a/packages/frontend/core/src/blocksuite/presets/effects.ts b/packages/frontend/core/src/blocksuite/presets/effects.ts
index 5dcedf3b8d..fe5fa87e6a 100644
--- a/packages/frontend/core/src/blocksuite/presets/effects.ts
+++ b/packages/frontend/core/src/blocksuite/presets/effects.ts
@@ -11,6 +11,7 @@ import {
import { ImagePlaceholder } from '../blocks/ai-chat-block/components/image-placeholder';
import { UserInfo } from '../blocks/ai-chat-block/components/user-info';
import { TextRenderer } from './_common/components/text-renderer';
+import { effects as componentAiItemEffects } from './ai/_common/components/ai-item';
import { AskAIButton } from './ai/_common/components/ask-ai-button';
import { AskAIIcon } from './ai/_common/components/ask-ai-icon';
import { AskAIPanel } from './ai/_common/components/ask-ai-panel';
@@ -61,9 +62,10 @@ import {
} from './ai/widgets/edgeless-copilot';
import { EdgelessCopilotPanel } from './ai/widgets/edgeless-copilot-panel';
import { EdgelessCopilotToolbarEntry } from './ai/widgets/edgeless-copilot-panel/toolbar-entry';
-
export function registerBlocksuitePresetsCustomComponents() {
registerMiniMindmapBlocks();
+ componentAiItemEffects();
+
customElements.define('ask-ai-icon', AskAIIcon);
customElements.define('ask-ai-button', AskAIButton);
customElements.define('ask-ai-toolbar-button', AskAIToolbarButton);
diff --git a/packages/frontend/core/src/components/blocksuite/block-suite-editor/ai/copilot-client.ts b/packages/frontend/core/src/components/blocksuite/block-suite-editor/ai/copilot-client.ts
index 5ded4c0bcc..6eda8caa4f 100644
--- a/packages/frontend/core/src/components/blocksuite/block-suite-editor/ai/copilot-client.ts
+++ b/packages/frontend/core/src/components/blocksuite/block-suite-editor/ai/copilot-client.ts
@@ -1,3 +1,8 @@
+import {
+ GeneralNetworkError,
+ PaymentRequiredError,
+ UnauthorizedError,
+} from '@affine/core/blocksuite/presets/ai/_common/components/ai-item/types';
import { showAILoginRequiredAtom } from '@affine/core/components/affine/auth/ai-login-required';
import {
addContextDocMutation,
@@ -20,11 +25,6 @@ import {
updateCopilotSessionMutation,
UserFriendlyError,
} from '@affine/graphql';
-import {
- GeneralNetworkError,
- PaymentRequiredError,
- UnauthorizedError,
-} from '@blocksuite/affine/blocks';
import { getCurrentStore } from '@toeverything/infra';
type OptionsField<T extends GraphQLQuery> =