feat(ai): bind each conversation to its own connection
This commit is contained in:
1 parent
47e7f56b14
commit
c373f322d2
35 files changed
+1584
-272
No files matched your search
@@ -4,13 +4,7 @@ import type { QueryEditorTableReferenceDropDetail, QueryEditorTableReferencePayl
|
||||
/** Selector marking the AI assistant panel root as a table-reference drop target. */
|
||||
export const AI_ASSISTANT_TABLE_DROP_ROOT_SELECTOR = "[data-ai-assistant-root]";
|
||||
|
||||
export interface AiTableReferenceDropContext {
|
||||
connectionId?: string;
|
||||
database?: string;
|
||||
}
|
||||
|
||||
export interface AiTableReferenceDropHandlerOptions {
|
||||
context: AiTableReferenceDropContext;
|
||||
assistantRoot: Element | null | undefined;
|
||||
elementFromPoint: (x: number, y: number) => Element | null;
|
||||
onMention: (mention: AiTableMention, payload: QueryEditorTableReferencePayload) => void;
|
||||
@@ -20,10 +14,18 @@ export interface AiTableReferenceDropHandlerOptions {
|
||||
* Maps a sidebar table-reference drag payload to an AI table mention chip.
|
||||
* Only plain table/view references become mentions; database and column
|
||||
* references are not representable as table mentions and return null.
|
||||
*
|
||||
* The payload's connection/database are deliberately NOT matched against a
|
||||
* fixed composer context. That rejection was the right answer while the panel's
|
||||
* connection was whatever editor tab was active — there was nothing to retarget,
|
||||
* so a foreign table had to be dropped. Now the conversation owns its binding
|
||||
* (#9902), so a table dragged in from elsewhere *retargets the conversation*
|
||||
* (see `applyExternalBinding`), which is both what the drag means and what makes
|
||||
* the mention resolvable. A caller that wants to refuse a foreign table must
|
||||
* decide that after this function returns.
|
||||
*/
|
||||
export function aiTableMentionFromTableReference(payload: QueryEditorTableReferencePayload | null | undefined, context: AiTableReferenceDropContext): AiTableMention | null {
|
||||
export function aiTableMentionFromTableReference(payload: QueryEditorTableReferencePayload | null | undefined): AiTableMention | null {
|
||||
if (!payload || payload.referenceType === "database" || payload.columnName) return null;
|
||||
if (!context.connectionId || context.database == null || payload.connectionId !== context.connectionId || payload.database !== context.database) return null;
|
||||
const table = payload.tableName;
|
||||
if (!table) return null;
|
||||
const schema = payload.schema;
|
||||
@@ -36,7 +38,7 @@ export function handleAiTableReferenceDropEvent(event: Event, options: AiTableRe
|
||||
if (!detail?.payload) return false;
|
||||
const target = options.elementFromPoint(detail.clientX, detail.clientY);
|
||||
if (!target || !options.assistantRoot?.contains(target)) return false;
|
||||
const mention = aiTableMentionFromTableReference(detail.payload, options.context);
|
||||
const mention = aiTableMentionFromTableReference(detail.payload);
|
||||
if (!mention) return false;
|
||||
options.onMention(mention, detail.payload);
|
||||
return true;
|
||||
|
||||
Reference in new issue
Block a user