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 72573cd68e..7530b7e2fc 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
@@ -364,8 +364,7 @@ export class ChatPanelInput extends WithDisposable(LitElement) {
}}
@keydown=${async (evt: KeyboardEvent) => {
if (evt.key === 'Enter' && !evt.shiftKey && !evt.isComposing) {
- evt.preventDefault();
- await this.send();
+ this._onTextareaSend(evt);
}
}}
@focus=${() => {
@@ -425,7 +424,7 @@ export class ChatPanelInput extends WithDisposable(LitElement) {
${ChatAbortIcon}
`
: html`
`;
}
- send = async (input?: string) => {
+ private readonly _onTextareaSend = (e: MouseEvent | KeyboardEvent) => {
+ e.preventDefault();
+ e.stopPropagation();
+
+ const value = this.textarea.value.trim();
+ if (value.length === 0) return;
+
+ this.textarea.value = '';
+ this.isInputEmpty = true;
+ this.textarea.style.height = 'unset';
+
+ this.send(value).catch(console.error);
+ };
+
+ send = async (text: string) => {
const { status, markdown } = this.chatContextValue;
if (status === 'loading' || status === 'transmitting') return;
- const text = input || this.textarea.value;
const { images } = this.chatContextValue;
if (!text && images.length === 0) {
return;
}
const { doc } = this.host;
- this.textarea.value = '';
- this.isInputEmpty = true;
- this.textarea.style.height = 'unset';
+
this.updateContext({
images: [],
status: 'loading',
diff --git a/packages/frontend/core/src/blocksuite/presets/ai/provider.ts b/packages/frontend/core/src/blocksuite/presets/ai/provider.ts
index 2fcac2e24e..cb5a22a23a 100644
--- a/packages/frontend/core/src/blocksuite/presets/ai/provider.ts
+++ b/packages/frontend/core/src/blocksuite/presets/ai/provider.ts
@@ -25,7 +25,7 @@ export interface AIChatParams {
export interface AISendParams {
host: EditorHost;
- input?: string;
+ input: string;
context?: Partial;
}