fix(core): chat input will be sent repeatedly in two documents with split view (#9289)

Fix issue [AF-2011](https://linear.app/affine-design/issue/AF-2011).

Add `host` strict equality check before ai request send.
This commit is contained in:
akumatus
2024-12-24 11:17:42 +00:00
parent 6c0544b239
commit 7bd980991e
4 changed files with 20 additions and 7 deletions

View File

@@ -74,7 +74,11 @@ export class AskAIToolbarButton extends WithDisposable(LitElement) {
AIProvider.slots.requestOpenWithChat.emit({ host: this.host });
extractContext(this.host)
.then(context => {
AIProvider.slots.requestSendWithChat.emit({ input, context });
AIProvider.slots.requestSendWithChat.emit({
input,
context,
host: this.host,
});
})
.catch(console.error);
};

View File

@@ -300,11 +300,15 @@ export class ChatPanelInput extends WithDisposable(LitElement) {
super.connectedCallback();
this._disposables.add(
AIProvider.slots.requestSendWithChat.on(async ({ input, context }) => {
context && this.updateContext(context);
await this.updateComplete;
await this.send(input);
})
AIProvider.slots.requestSendWithChat.on(
async ({ input, context, host }) => {
if (this.host === host) {
context && this.updateContext(context);
await this.updateComplete;
await this.send(input);
}
}
)
);
}

View File

@@ -51,7 +51,11 @@ export function setupEdgelessElementToolbarAIEntry(
AIProvider.slots.requestOpenWithChat.emit({ host: edgeless.host });
extractContext(edgeless.host)
.then(context => {
AIProvider.slots.requestSendWithChat.emit({ input, context });
AIProvider.slots.requestSendWithChat.emit({
input,
context,
host: edgeless.host,
});
})
.catch(console.error);
};

View File

@@ -24,6 +24,7 @@ export interface AIChatParams {
}
export interface AISendParams {
host: EditorHost;
input?: string;
context?: Partial<ChatContextValue | null>;
}