From f7c86549879582c7f9dc72d52524f3a394f493f3 Mon Sep 17 00:00:00 2001 From: centdix <40307056+centdix@users.noreply.github.com> Date: Mon, 31 Mar 2025 14:37:49 +0200 Subject: [PATCH 1/5] feat: put db resources in ai context (#5507) * allow mentioning specific files in instructions * remove not working highlight implementation * make highlighted text work * fix tooltip position * clean code * cleaning * use lib for tooltip positioning * fix logic * draft for db in context * use tools for db in context * fixes * cleaning and bug fixes * fix * cleaning * fix when script is db type * simplify logic * put schema in context if already here * fix imports * fix tooltip position and make it scrollable * remove console logs * check if selected is in available * fix tooltip list * add back lost logic * last fix * fix type errors * use loaded schema from dbSchemas * fix typing, content and lang are always there * remove from context if not available anymore * add not loaded yet mention if schema not loaded * add missing callback logic * fix prompt * fix usage of updateselectedContext function * fix styling for white theme * handle tab and arrows * fix schemas not being refreshed on contexts * also refresh displayMessages when dbschemas change * fix duplicate available contexts * fix logic for new scripts * fix new lines inside text area * format files * fix number of db resources fetches * remove padding * fix tooltip y position --------- Co-authored-by: HugoCasa --- frontend/package-lock.json | 7 + frontend/package.json | 1 + .../lib/components/copilot/chat/AIChat.svelte | 218 ++++++++++-------- .../copilot/chat/AIChatDisplay.svelte | 157 ++++++------- .../copilot/chat/AvailableContextList.svelte | 40 ++++ .../copilot/chat/ContextElementBadge.svelte | 6 +- .../copilot/chat/ContextTextarea.svelte | 218 ++++++++++++++++++ .../src/lib/components/copilot/chat/core.ts | 99 +++++--- frontend/src/lib/stores.ts | 10 +- 9 files changed, 535 insertions(+), 221 deletions(-) create mode 100644 frontend/src/lib/components/copilot/chat/AvailableContextList.svelte create mode 100644 frontend/src/lib/components/copilot/chat/ContextTextarea.svelte diff --git a/frontend/package-lock.json b/frontend/package-lock.json index e8a77bc11a..64124a9a65 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -62,6 +62,7 @@ "svelte-infinite-loading": "^1.4.0", "svelte-tiny-virtual-list": "^2.0.5", "tailwind-merge": "^1.13.2", + "textarea-caret": "^3.1.0", "vscode": "npm:@codingame/monaco-vscode-api@~11.1.2", "vscode-languageclient": "~9.0.1", "vscode-uri": "~3.0.8", @@ -11881,6 +11882,12 @@ "integrity": "sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==", "dev": true }, + "node_modules/textarea-caret": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/textarea-caret/-/textarea-caret-3.1.0.tgz", + "integrity": "sha512-cXAvzO9pP5CGa6NKx0WYHl+8CHKZs8byMkt3PCJBCmq2a34YA9pO1NrQET5pzeqnBjBdToF5No4rrmkDUgQC2Q==", + "license": "MIT" + }, "node_modules/thenify": { "version": "3.3.1", "resolved": "https://registry.npmjs.org/thenify/-/thenify-3.3.1.tgz", diff --git a/frontend/package.json b/frontend/package.json index 2580cd35f0..ab203c2b47 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -138,6 +138,7 @@ "svelte-infinite-loading": "^1.4.0", "svelte-tiny-virtual-list": "^2.0.5", "tailwind-merge": "^1.13.2", + "textarea-caret": "^3.1.0", "vscode": "npm:@codingame/monaco-vscode-api@~11.1.2", "vscode-languageclient": "~9.0.1", "vscode-uri": "~3.0.8", diff --git a/frontend/src/lib/components/copilot/chat/AIChat.svelte b/frontend/src/lib/components/copilot/chat/AIChat.svelte index d27077d989..848dd77f9f 100644 --- a/frontend/src/lib/components/copilot/chat/AIChat.svelte +++ b/frontend/src/lib/components/copilot/chat/AIChat.svelte @@ -1,5 +1,12 @@
@@ -188,97 +196,74 @@ > -
- {#if availableContext.filter((c) => !selectedContext.find((sc) => sc.type === c.type)).length === 0} -
No available context
- {:else} - {#each availableContext as element} - {#if !selectedContext.find((c) => c.type === element.type)} - - {/if} - {/each} - {/if} -
+ { + addContextToSelection(element) + close() + }} + />
{#each selectedContext as element} - {@const contextElement = availableContext.find((c) => c.type === element.type)} + {@const contextElement = availableContext.find( + (c) => c.type === element.type && c.title === element.title + )} {#if contextElement} { - selectedContext = selectedContext.filter((c) => c.type !== element.type) + selectedContext = selectedContext.filter( + (c) => c.type !== element.type || c.title !== element.title + ) }} /> {/if} {/each}
-
-