diff --git a/packages/frontend/core/src/blocksuite/ai/components/ai-chat-chips/chat-panel-chips.ts b/packages/frontend/core/src/blocksuite/ai/components/ai-chat-chips/chat-panel-chips.ts
index 7e896be57..2bddd6f18 100644
--- a/packages/frontend/core/src/blocksuite/ai/components/ai-chat-chips/chat-panel-chips.ts
+++ b/packages/frontend/core/src/blocksuite/ai/components/ai-chat-chips/chat-panel-chips.ts
@@ -100,6 +100,9 @@ export class ChatPanelChips extends SignalWatcher(
@property({ attribute: false })
accessor searchMenuConfig!: SearchMenuConfig;
+ @property({ attribute: false })
+ accessor portalContainer: HTMLElement | null = null;
+
@property({ attribute: 'data-testid', reflect: true })
accessor testId = 'chat-panel-chips';
@@ -267,7 +270,7 @@ export class ChatPanelChips extends SignalWatcher(
portalStyles: {
zIndex: 'var(--affine-z-index-popover)',
},
- container: document.body,
+ container: this.portalContainer ?? document.body,
computePosition: {
referenceElement: this.addButton,
placement: 'top-start',
@@ -306,7 +309,7 @@ export class ChatPanelChips extends SignalWatcher(
portalStyles: {
zIndex: 'var(--affine-z-index-popover)',
},
- container: document.body,
+ container: this.portalContainer ?? document.body,
computePosition: {
referenceElement: this.moreCandidateButton,
placement: 'top-start',
diff --git a/packages/frontend/core/src/blocksuite/ai/peek-view/chat-block-peek-view.ts b/packages/frontend/core/src/blocksuite/ai/peek-view/chat-block-peek-view.ts
index d27be9e86..e31d76b2a 100644
--- a/packages/frontend/core/src/blocksuite/ai/peek-view/chat-block-peek-view.ts
+++ b/packages/frontend/core/src/blocksuite/ai/peek-view/chat-block-peek-view.ts
@@ -23,6 +23,11 @@ import {
queryHistoryMessages,
} from '../_common/chat-actions-handle';
import { type AIChatBlockModel } from '../blocks';
+import type {
+ ChatChip,
+ DocDisplayConfig,
+ SearchMenuConfig,
+} from '../components/ai-chat-chips';
import type { AINetworkSearchConfig } from '../components/ai-chat-input';
import type { ChatMessage } from '../components/ai-chat-messages';
import { ChatMessagesSchema } from '../components/ai-chat-messages';
@@ -155,6 +160,16 @@ export class AIChatBlockPeekView extends LitElement {
};
private readonly _getContextId = async () => {
+ if (this._chatContextId) {
+ return this._chatContextId;
+ }
+ const sessionId = await this._getSessionId();
+ if (sessionId) {
+ this._chatContextId = await AIProvider.context?.createContext(
+ this.host.doc.workspace.id,
+ sessionId
+ );
+ }
return this._chatContextId;
};
@@ -273,6 +288,10 @@ export class AIChatBlockPeekView extends LitElement {
this.chatContext = { ...this.chatContext, ...context };
};
+ updateChips = (chips: ChatChip[]) => {
+ this.chips = chips;
+ };
+
/**
* Clean current chat messages and delete the newly created AI chat block
*/
@@ -524,6 +543,7 @@ export class AIChatBlockPeekView extends LitElement {