From b32c36fb9b8d7f53cba302526e51524951643418 Mon Sep 17 00:00:00 2001 From: Test Date: Mon, 23 Sep 2024 16:56:09 -0700 Subject: [PATCH 1/8] updated configs --- docs/static/schemas/config.json | 8 ++++++++ extensions/intellij/src/main/resources/config_schema.json | 7 +++++++ extensions/vscode/continue_rc_schema.json | 7 +++++++ 3 files changed, 22 insertions(+) diff --git a/docs/static/schemas/config.json b/docs/static/schemas/config.json index 911278ebb..176bbd295 100644 --- a/docs/static/schemas/config.json +++ b/docs/static/schemas/config.json @@ -1044,6 +1044,7 @@ "llama2-70b", "mistral-8x7b", "gemma", + "gemma2", "llama3-8b", "llama3-70b", "llama3.1-8b", @@ -2114,6 +2115,13 @@ "minimum": 128, "exclusiveMaximum": 2147483647 }, + "maxBatchSize": { + "title": "Maximum Batch Size", + "description": "The maximum number of chunks that can be sent to the embeddings provider in a single request", + "type": "integer", + "minimum": 1, + "exclusiveMaximum": 2147483647 + }, "region": { "title": "Region", "description": "The region where the model is hosted", diff --git a/extensions/intellij/src/main/resources/config_schema.json b/extensions/intellij/src/main/resources/config_schema.json index 5a20c6daf..176bbd295 100644 --- a/extensions/intellij/src/main/resources/config_schema.json +++ b/extensions/intellij/src/main/resources/config_schema.json @@ -2115,6 +2115,13 @@ "minimum": 128, "exclusiveMaximum": 2147483647 }, + "maxBatchSize": { + "title": "Maximum Batch Size", + "description": "The maximum number of chunks that can be sent to the embeddings provider in a single request", + "type": "integer", + "minimum": 1, + "exclusiveMaximum": 2147483647 + }, "region": { "title": "Region", "description": "The region where the model is hosted", diff --git a/extensions/vscode/continue_rc_schema.json b/extensions/vscode/continue_rc_schema.json index 7a7e54764..8a1c0bca0 100644 --- a/extensions/vscode/continue_rc_schema.json +++ b/extensions/vscode/continue_rc_schema.json @@ -2356,6 +2356,13 @@ "minimum": 128, "exclusiveMaximum": 2147483647 }, + "maxBatchSize": { + "title": "Maximum Batch Size", + "description": "The maximum number of chunks that can be sent to the embeddings provider in a single request", + "type": "integer", + "minimum": 1, + "exclusiveMaximum": 2147483647 + }, "region": { "title": "Region", "description": "The region where the model is hosted", From 5105645dedec92abd3fc613777f60fd2a638a0ab Mon Sep 17 00:00:00 2001 From: Test Date: Mon, 23 Sep 2024 18:25:56 -0700 Subject: [PATCH 2/8] fix: add new UI breakpoints --- .../OnboardingCard/OnboardingCard.tsx | 5 +- .../components/BestExperienceConfigForm.tsx | 10 +- .../components/OllamaCompletedStep.tsx | 2 +- .../components/OllamaModelDownload.tsx | 2 +- .../components/OllamaStatus.tsx | 4 +- .../components/OnboardingCardTabs.tsx | 85 +++++++++---- .../components/ProviderAlert.tsx | 2 +- .../OnboardingCard/tabs/OnboardingBestTab.tsx | 4 +- .../tabs/OnboardingQuickstartTab.tsx | 10 +- gui/src/components/gui/StepContainer.tsx | 6 +- gui/src/components/mainInput/InputToolbar.tsx | 24 ++-- .../components/modelSelection/ModelSelect.tsx | 118 +++++++++--------- gui/tailwind.config.cjs | 9 +- 13 files changed, 166 insertions(+), 115 deletions(-) diff --git a/gui/src/components/OnboardingCard/OnboardingCard.tsx b/gui/src/components/OnboardingCard/OnboardingCard.tsx index 251ff7b1c..aba23e14a 100644 --- a/gui/src/components/OnboardingCard/OnboardingCard.tsx +++ b/gui/src/components/OnboardingCard/OnboardingCard.tsx @@ -9,7 +9,6 @@ import { useOnboardingCard } from "./hooks/useOnboardingCard"; const StyledCard = styled.div` margin: auto; border-radius: ${defaultBorderRadius}; - padding: 1rem 1.5rem; background-color: ${vscInputBackground}; box-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1); @@ -43,13 +42,13 @@ export function OnboardingCard(props: OnboardingCardProps) { } return ( - + - +
{renderTabContent()}
diff --git a/gui/src/components/OnboardingCard/components/BestExperienceConfigForm.tsx b/gui/src/components/OnboardingCard/components/BestExperienceConfigForm.tsx index ee061e1f9..f38fbaccd 100644 --- a/gui/src/components/OnboardingCard/components/BestExperienceConfigForm.tsx +++ b/gui/src/components/OnboardingCard/components/BestExperienceConfigForm.tsx @@ -65,13 +65,13 @@ function BestExperienceConfigForm({
{chatModel.title}{" "} - by Anthropic + by Anthropic
@@ -99,13 +99,13 @@ function BestExperienceConfigForm({
{autocompleteModel.title}{" "} - by Mistral + by Mistral
@@ -129,7 +129,7 @@ function BestExperienceConfigForm({ -
+
diff --git a/gui/src/components/OnboardingCard/components/OllamaCompletedStep.tsx b/gui/src/components/OnboardingCard/components/OllamaCompletedStep.tsx index ee3eb942c..44c5c5caa 100644 --- a/gui/src/components/OnboardingCard/components/OllamaCompletedStep.tsx +++ b/gui/src/components/OnboardingCard/components/OllamaCompletedStep.tsx @@ -7,7 +7,7 @@ interface OllamaCompletedStepProps { function OllamaCompletedStep({ text }: OllamaCompletedStepProps) { return (
-

{text}

+

{text}

); diff --git a/gui/src/components/OnboardingCard/components/OllamaModelDownload.tsx b/gui/src/components/OnboardingCard/components/OllamaModelDownload.tsx index 37831a70f..721807c6a 100644 --- a/gui/src/components/OnboardingCard/components/OllamaModelDownload.tsx +++ b/gui/src/components/OnboardingCard/components/OllamaModelDownload.tsx @@ -35,7 +35,7 @@ function OllamaModelDownload({ ) : ( <> -

{command}

+

{command}

{tooltipPortalDiv && diff --git a/gui/src/components/OnboardingCard/components/OllamaStatus.tsx b/gui/src/components/OnboardingCard/components/OllamaStatus.tsx index 9cc323ec6..39bd7978c 100644 --- a/gui/src/components/OnboardingCard/components/OllamaStatus.tsx +++ b/gui/src/components/OnboardingCard/components/OllamaStatus.tsx @@ -35,14 +35,14 @@ export function OllamaStatus({ isOllamaConnected }: OllamaStatusProps) { case OllamaConnectionStatuses.WaitingToDownload: return ( -

{downloadUrl}

+

{downloadUrl}

); case OllamaConnectionStatuses.Downloading: return (
-

+

Checking for connection to Ollama at http://localhost:11434

diff --git a/gui/src/components/OnboardingCard/components/OnboardingCardTabs.tsx b/gui/src/components/OnboardingCard/components/OnboardingCardTabs.tsx index 7e7fcdcee..d44524cb5 100644 --- a/gui/src/components/OnboardingCard/components/OnboardingCardTabs.tsx +++ b/gui/src/components/OnboardingCard/components/OnboardingCardTabs.tsx @@ -9,23 +9,39 @@ interface OnboardingCardTabsProps { export type TabTitle = "Quickstart" | "Best" | "Local"; -export const TabTitles: { [k in TabTitle]: { xs: string; default: string } } = { +export const TabTitles: { [k in TabTitle]: { md: string; default: string } } = { Quickstart: { - xs: "Quickstart", + md: "Quickstart", default: "Quickstart", }, Best: { - xs: "Best", + md: "Best", default: "Best experience", }, Local: { - xs: "Local", + md: "Local", default: "Local with Ollama", }, }; +const StyledSelect = styled.select` + width: 100%; + padding: 0.5rem; + background-color: transparent; + color: ${vscForeground}; + border: none; + border-bottom: 1px solid ${vscForeground}; + border-radius: 0; + font-size: 1rem; + cursor: pointer; + display: block; + + &:focus { + outline: none; + } +`; + const TabButton = styled.button<{ isActive: boolean }>` - padding: 1rem 1rem 0.5rem 1rem; margin-bottom: -1px; focus: outline-none; background: transparent; @@ -54,23 +70,48 @@ export function OnboardingCardTabs({ onTabClick, }: OnboardingCardTabsProps) { return ( - - {Object.entries(TabTitles).map(([tabType, titles]) => { - if (hasPassedFTL() && tabType === "Quickstart") { - return undefined; - } +
+
+ + {Object.entries(TabTitles).map(([tabType, titles]) => { + if (hasPassedFTL() && tabType === "Quickstart") { + return undefined; + } - return ( - onTabClick(tabType as TabTitle)} - > -

{titles.default}

-

{titles.xs}

-
- ); - })} -
+ return ( + onTabClick(tabType as TabTitle)} + > +

+ {titles.default} +

+

{titles.md}

+
+ ); + })} + +
+
+ onTabClick(e.target.value as TabTitle)} + > + {Object.entries(TabTitles).map(([tabType, titles]) => { + if (hasPassedFTL() && tabType === "Quickstart") { + return null; + } + + return ( + + ); + })} + +
+
); } diff --git a/gui/src/components/OnboardingCard/components/ProviderAlert.tsx b/gui/src/components/OnboardingCard/components/ProviderAlert.tsx index dd1e9f339..8c2c1ca6f 100644 --- a/gui/src/components/OnboardingCard/components/ProviderAlert.tsx +++ b/gui/src/components/OnboardingCard/components/ProviderAlert.tsx @@ -17,7 +17,7 @@ function ProviderAlert() { } return ( -
+

Prefer to use an different provider like OpenAI? diff --git a/gui/src/components/OnboardingCard/tabs/OnboardingBestTab.tsx b/gui/src/components/OnboardingCard/tabs/OnboardingBestTab.tsx index 0f5e5f441..d5b372245 100644 --- a/gui/src/components/OnboardingCard/tabs/OnboardingBestTab.tsx +++ b/gui/src/components/OnboardingCard/tabs/OnboardingBestTab.tsx @@ -7,7 +7,9 @@ function OnboardingBestTab() { return (

- +
+ +
); diff --git a/gui/src/components/OnboardingCard/tabs/OnboardingQuickstartTab.tsx b/gui/src/components/OnboardingCard/tabs/OnboardingQuickstartTab.tsx index f0eadf43b..ff77e18e8 100644 --- a/gui/src/components/OnboardingCard/tabs/OnboardingQuickstartTab.tsx +++ b/gui/src/components/OnboardingCard/tabs/OnboardingQuickstartTab.tsx @@ -3,18 +3,18 @@ import QuickStartSubmitButton from "../components/QuickStartSubmitButton"; function OnboardingQuickstartTab() { return ( -
-
-
+
+
+
-

+

Quickly get up and running using our API keys. After this trial, we'll help you set up your own models.

-

+

To prevent abuse, we'll ask you to sign in to GitHub.

diff --git a/gui/src/components/gui/StepContainer.tsx b/gui/src/components/gui/StepContainer.tsx index 48f8cbc2a..9354a73b5 100644 --- a/gui/src/components/gui/StepContainer.tsx +++ b/gui/src/components/gui/StepContainer.tsx @@ -124,14 +124,14 @@ function StepContainer(props: StepContainerProps) { {(props.isLast || isHovered || typeof feedback !== "undefined") && !active && (
{props.modelTitle && ( - <> +
{props.modelTitle}
- +
)} {truncatedEarly && ( diff --git a/gui/src/components/mainInput/InputToolbar.tsx b/gui/src/components/mainInput/InputToolbar.tsx index a95a71502..907ff7fed 100644 --- a/gui/src/components/mainInput/InputToolbar.tsx +++ b/gui/src/components/mainInput/InputToolbar.tsx @@ -207,17 +207,19 @@ function InputToolbar(props: InputToolbarProps) { {getMetaKeyLabel()} ⏎ Use @codebase )} - { - props.onEnter({ - useCodebase: isMetaEquivalentKeyPressed(e), - noContext: useActiveFile ? e.altKey : !e.altKey, - }); - }} - > - ⏎ Enter - +
+ { + props.onEnter({ + useCodebase: isMetaEquivalentKeyPressed(e), + noContext: useActiveFile ? e.altKey : !e.altKey, + }); + }} + > + ⏎ Enter + +
diff --git a/gui/src/components/modelSelection/ModelSelect.tsx b/gui/src/components/modelSelection/ModelSelect.tsx index 548d83537..cfa3a2fe1 100644 --- a/gui/src/components/modelSelection/ModelSelect.tsx +++ b/gui/src/components/modelSelection/ModelSelect.tsx @@ -304,65 +304,67 @@ function ModelSelect() { } return ( - { - if (val === defaultModel?.title) return; - dispatch(setDefaultModel({ title: val })); - await ideMessenger.request("update/modelChange", val); - }} - > -
- - - {modelSelectTitle(defaultModel) || "Select model"}{" "} - - - -
- {sortedOptions.map((option, idx) => ( - 1} - showMissingApiKeyMsg={option.apiKey === ""} - /> - ))} -
- -
- {selectedProfileId === "local" && ( - <> - {options.length > 0 && } - - -
- - Add Chat model -
-
- - )} - - - - - {getMetaKeyLabel()} + ' to toggle +
+ { + if (val === defaultModel?.title) return; + dispatch(setDefaultModel({ title: val })); + await ideMessenger.request("update/modelChange", val); + }} + > +
+ + + {modelSelectTitle(defaultModel) || "Select model"}{" "} + -
- -
- + + +
+ {sortedOptions.map((option, idx) => ( + 1} + showMissingApiKeyMsg={option.apiKey === ""} + /> + ))} +
+ +
+ {selectedProfileId === "local" && ( + <> + {options.length > 0 && } + + +
+ + Add Chat model +
+
+ + )} + + + + + {getMetaKeyLabel()} + ' to toggle + +
+
+
+ +
); } diff --git a/gui/tailwind.config.cjs b/gui/tailwind.config.cjs index 26c9495f5..ffea05a7d 100644 --- a/gui/tailwind.config.cjs +++ b/gui/tailwind.config.cjs @@ -9,8 +9,13 @@ module.exports = { ], theme: { screens: { - xs: "425px", - ...defaultTheme.screens, + xxs: "170px", // Smallest width for Primary Sidebar in VS Code + xs: "250px", // Default sidebar width in VS Code + sm: "320px", + md: "480px", + lg: "640px", // Tailwind's default 'sm' + xl: "768px", // Tailwind's default 'md' + "2xl": "1024px", // Tailwind's default 'lg' }, extend: { animation: { From 49261a611788784fe7f2b91630764dcfb4f6cf72 Mon Sep 17 00:00:00 2001 From: Test Date: Mon, 23 Sep 2024 18:36:20 -0700 Subject: [PATCH 3/8] remove input toolbar on smallest breakpoint --- gui/src/components/mainInput/InputToolbar.tsx | 2 +- gui/src/components/mainInput/TipTapEditor.tsx | 1 + .../components/modelSelection/ModelSelect.tsx | 118 +++++++++--------- 3 files changed, 60 insertions(+), 61 deletions(-) diff --git a/gui/src/components/mainInput/InputToolbar.tsx b/gui/src/components/mainInput/InputToolbar.tsx index 907ff7fed..367741b27 100644 --- a/gui/src/components/mainInput/InputToolbar.tsx +++ b/gui/src/components/mainInput/InputToolbar.tsx @@ -28,7 +28,6 @@ import ModelSelect from "../modelSelection/ModelSelect"; const StyledDiv = styled.div<{ isHidden: boolean }>` padding: 4px 0; - display: flex; justify-content: space-between; gap: 1px; background-color: ${vscInputBackground}; @@ -110,6 +109,7 @@ function InputToolbar(props: InputToolbarProps) { isHidden={props.hidden} onClick={props.onClick} id="input-toolbar" + className="hidden xs:flex" > diff --git a/gui/src/components/mainInput/TipTapEditor.tsx b/gui/src/components/mainInput/TipTapEditor.tsx index 2fc543907..a57d19bda 100644 --- a/gui/src/components/mainInput/TipTapEditor.tsx +++ b/gui/src/components/mainInput/TipTapEditor.tsx @@ -894,6 +894,7 @@ function TipTapEditor(props: TipTapEditorProps) { }); }} /> + {showDragOverMsg && modelSupportsImages( defaultModel.provider, diff --git a/gui/src/components/modelSelection/ModelSelect.tsx b/gui/src/components/modelSelection/ModelSelect.tsx index cfa3a2fe1..548d83537 100644 --- a/gui/src/components/modelSelection/ModelSelect.tsx +++ b/gui/src/components/modelSelection/ModelSelect.tsx @@ -304,67 +304,65 @@ function ModelSelect() { } return ( -
- { - if (val === defaultModel?.title) return; - dispatch(setDefaultModel({ title: val })); - await ideMessenger.request("update/modelChange", val); - }} - > -
- - - {modelSelectTitle(defaultModel) || "Select model"}{" "} -
+ +
+
); } From 423926e507a5c373b01246c99a844ae1da927499 Mon Sep 17 00:00:00 2001 From: Test Date: Mon, 23 Sep 2024 19:01:05 -0700 Subject: [PATCH 4/8] Update CodeBlockToolbar.tsx --- gui/src/components/markdown/CodeBlockToolbar.tsx | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/gui/src/components/markdown/CodeBlockToolbar.tsx b/gui/src/components/markdown/CodeBlockToolbar.tsx index 5fdb5880c..417d33dbb 100644 --- a/gui/src/components/markdown/CodeBlockToolbar.tsx +++ b/gui/src/components/markdown/CodeBlockToolbar.tsx @@ -28,6 +28,7 @@ import FileIcon from "../FileIcon"; import ButtonWithTooltip from "../ButtonWithTooltip"; import { CopyButton as CopyButtonHeader } from "./CopyButton"; import { ToolbarButtonWithTooltip } from "./ToolbarButtonWithTooltip"; +import { getBasename } from "core/util"; const ToolbarDiv = styled.div` display: flex; @@ -217,11 +218,15 @@ function CodeBlockToolBar(props: CodeBlockToolBarProps) { return (
- {props.filepath}{" "} +
+ + {getBasename(props.filepath)} + +
@@ -233,12 +238,12 @@ function CodeBlockToolBar(props: CodeBlockToolBarProps) { {isCopied ? ( <> - Copied + Copied ) : ( <> - Copy + Copy )}
@@ -256,7 +261,7 @@ function CodeBlockToolBar(props: CodeBlockToolBarProps) { style={{ color: lightGray }} > - Apply + Apply
) : ( From 6ecbd23a012f7140626473d2b3215ee67b5e14e0 Mon Sep 17 00:00:00 2001 From: Test Date: Tue, 24 Sep 2024 15:59:03 -0700 Subject: [PATCH 5/8] gui: improve input breakpoints and context peek --- core/commands/util.ts | 4 +- .../providers/CurrentFileContextProvider.ts | 10 +- core/context/providers/FileContextProvider.ts | 4 + .../providers/OpenFilesContextProvider.ts | 9 +- core/context/providers/URLContextProvider.ts | 10 +- core/context/retrieval/retrieval.ts | 34 ++- core/index.d.ts | 16 +- core/indexing/CodeSnippetsIndex.ts | 4 + core/indexing/docs/DocsService.ts | 50 ++-- core/util/fetchFavicon.ts | 65 +++++ .../components/mainInput/ContextItemsPeek.tsx | 228 ++++++++---------- gui/src/components/mainInput/InputToolbar.tsx | 176 ++++++-------- gui/src/components/mainInput/TipTapEditor.tsx | 19 +- .../components/modelSelection/ModelSelect.tsx | 13 +- gui/src/pages/gui.tsx | 9 +- gui/tailwind.config.cjs | 12 +- 16 files changed, 354 insertions(+), 309 deletions(-) create mode 100644 core/util/fetchFavicon.ts diff --git a/core/commands/util.ts b/core/commands/util.ts index 207b6c5ec..931564839 100644 --- a/core/commands/util.ts +++ b/core/commands/util.ts @@ -1,4 +1,4 @@ -import { ContextItemWithId } from "../index.js"; +import { ContextItemWithId } from "../"; export interface RangeInFileWithContents { filepath: string; @@ -15,7 +15,7 @@ export function contextItemToRangeInFileWithContents( const lines = item.name.split("(")[1].split(")")[0].split("-"); const rif: RangeInFileWithContents = { - filepath: item.id.itemId, + filepath: item.uri?.value || "", range: { start: { line: Number.parseInt(lines[0]), diff --git a/core/context/providers/CurrentFileContextProvider.ts b/core/context/providers/CurrentFileContextProvider.ts index e149c8079..575350b49 100644 --- a/core/context/providers/CurrentFileContextProvider.ts +++ b/core/context/providers/CurrentFileContextProvider.ts @@ -2,9 +2,9 @@ import { ContextItem, ContextProviderDescription, ContextProviderExtras, -} from "../../index.js"; -import { getBasename } from "../../util/index.js"; -import { BaseContextProvider } from "../index.js"; +} from "../../"; +import { getBasename } from "../../util/"; +import { BaseContextProvider } from "../"; class CurrentFileContextProvider extends BaseContextProvider { static description: ContextProviderDescription = { @@ -32,6 +32,10 @@ class CurrentFileContextProvider extends BaseContextProvider { currentFile, )}\n${contents}\n\`\`\``, name: getBasename(currentFile), + uri: { + type: "file", + value: currentFile, + }, }, ]; } diff --git a/core/context/providers/FileContextProvider.ts b/core/context/providers/FileContextProvider.ts index ef0bfeb54..be558c651 100644 --- a/core/context/providers/FileContextProvider.ts +++ b/core/context/providers/FileContextProvider.ts @@ -36,6 +36,10 @@ class FileContextProvider extends BaseContextProvider { name: query.split(/[\\/]/).pop() ?? query, description: query, content: `\`\`\`${query}\n${content}\n\`\`\``, + uri: { + type: "file", + value: query, + }, }, ]; } diff --git a/core/context/providers/OpenFilesContextProvider.ts b/core/context/providers/OpenFilesContextProvider.ts index b0c85bc2e..c00121a96 100644 --- a/core/context/providers/OpenFilesContextProvider.ts +++ b/core/context/providers/OpenFilesContextProvider.ts @@ -28,10 +28,15 @@ class OpenFilesContextProvider extends BaseContextProvider { openFiles.map(async (filepath: string) => { return { description: filepath, - content: `\`\`\`${await getRelativePath(filepath, workspaceDirs)}\n${await ide.readFile( + content: `\`\`\`${await getRelativePath( filepath, - )}\n\`\`\``, + workspaceDirs, + )}\n${await ide.readFile(filepath)}\n\`\`\``, name: (filepath.split("/").pop() ?? "").split("\\").pop() ?? "", + uri: { + type: "file", + value: filepath, + }, }; }), ); diff --git a/core/context/providers/URLContextProvider.ts b/core/context/providers/URLContextProvider.ts index 2e864fbb9..8a471ef45 100644 --- a/core/context/providers/URLContextProvider.ts +++ b/core/context/providers/URLContextProvider.ts @@ -1,12 +1,13 @@ import { Readability } from "@mozilla/readability"; import { JSDOM } from "jsdom"; import { NodeHtmlMarkdown } from "node-html-markdown"; -import { BaseContextProvider } from "../index.js"; +import { BaseContextProvider } from "../"; import { ContextItem, ContextProviderDescription, ContextProviderExtras, } from "../../index.js"; +import { fetchFavicon } from "../../util/fetchFavicon"; class URLContextProvider extends BaseContextProvider { static description: ContextProviderDescription = { @@ -22,6 +23,7 @@ class URLContextProvider extends BaseContextProvider { ): Promise { try { const url = new URL(query); + const icon = await fetchFavicon(url); const resp = await extras.fetch(url); const html = await resp.text(); @@ -37,11 +39,17 @@ class URLContextProvider extends BaseContextProvider { ); const title = article?.title || url.pathname; + return [ { + icon, description: title, content: markdown, name: title, + uri: { + type: "url", + value: url.toString(), + }, }, ]; } catch (e) { diff --git a/core/context/retrieval/retrieval.ts b/core/context/retrieval/retrieval.ts index 1b250e548..9d19a33f7 100644 --- a/core/context/retrieval/retrieval.ts +++ b/core/context/retrieval/retrieval.ts @@ -6,6 +6,7 @@ import { INSTRUCTIONS_BASE_ITEM } from "../providers/utils"; import { RetrievalPipelineOptions } from "./pipelines/BaseRetrievalPipeline"; import NoRerankerRetrievalPipeline from "./pipelines/NoRerankerRetrievalPipeline"; import RerankerRetrievalPipeline from "./pipelines/RerankerRetrievalPipeline"; +import path from "path"; export async function retrieveContextItemsFromEmbeddings( extras: ContextProviderExtras, @@ -94,21 +95,32 @@ export async function retrieveContextItemsFromEmbeddings( } return [ - ...results.map((r) => { - const name = `${getRelativePath(r.filepath, workspaceDirs)} (${ - r.startLine - }-${r.endLine})`; - const description = `${r.filepath} (${r.startLine}-${r.endLine})`; - return { - name, - description, - content: `\`\`\`${name}\n${r.content}\n\`\`\``, - }; - }), { ...INSTRUCTIONS_BASE_ITEM, content: "Use the above code to answer the following question. You should not reference any files outside of what is shown, unless they are commonly known files, like a .gitignore or package.json. Reference the filenames whenever possible. If there isn't enough information to answer the question, suggest where the user might look to learn more.", }, + ...results + .sort((a, b) => a.filepath.localeCompare(b.filepath)) + .map((r) => { + const name = `${path.basename(r.filepath)} (${r.startLine}-${ + r.endLine + })`; + const description = `${r.filepath}`; + + if (r.filepath.includes("package.json")) { + console.log(); + } + + return { + name, + description, + content: `\`\`\`${name}\n${r.content}\n\`\`\``, + uri: { + type: "file" as const, + value: r.filepath, + }, + }; + }), ]; } diff --git a/core/index.d.ts b/core/index.d.ts index 16c48a3ad..659f9f80c 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -271,6 +271,13 @@ export interface ContextItemId { itemId: string; } +export type ContextItemUriTypes = "file" | "url"; + +export interface ContextItemUri { + type: ContextItemUriTypes; + value: string; +} + export interface ContextItem { content: string; name: string; @@ -278,16 +285,11 @@ export interface ContextItem { editing?: boolean; editable?: boolean; icon?: string; + uri?: ContextItemUri; } -export interface ContextItemWithId { - content: string; - name: string; - description: string; +export interface ContextItemWithId extends ContextItem { id: ContextItemId; - editing?: boolean; - editable?: boolean; - icon?: string; } export interface InputModifiers { diff --git a/core/indexing/CodeSnippetsIndex.ts b/core/indexing/CodeSnippetsIndex.ts index 6a02babd4..a8b41cafe 100644 --- a/core/indexing/CodeSnippetsIndex.ts +++ b/core/indexing/CodeSnippetsIndex.ts @@ -341,6 +341,10 @@ export class CodeSnippetsCodebaseIndex implements CodebaseIndex { name: row.title, description: getLastNPathParts(row.path, 2), content: `\`\`\`${getBasename(row.path)}\n${row.content}\n\`\`\``, + uri: { + type: "file", + value: row.path, + }, }; } diff --git a/core/indexing/docs/DocsService.ts b/core/indexing/docs/DocsService.ts index de773e662..d54f49f10 100644 --- a/core/indexing/docs/DocsService.ts +++ b/core/indexing/docs/DocsService.ts @@ -32,6 +32,7 @@ import { SiteIndexingResults, } from "./preIndexed"; import preIndexedDocs from "./preIndexedDocs"; +import { fetchFavicon, getFaviconBase64 } from "../../util/fetchFavicon"; // Purposefully lowercase because lancedb converts export interface LanceDbDocsRow { @@ -154,7 +155,10 @@ export default class DocsService { params: {}, }); - this.ide.showToast("info", "Successfuly added docs context provider"); + await this.ide.showToast( + "info", + "Successfuly added docs context provider", + ); } return res === actionMsg; @@ -177,7 +181,7 @@ export default class DocsService { while (!(await generator.next()).done) {} } - this.ide.showToast("info", "Docs indexing completed"); + await this.ide.showToast("info", "Docs indexing completed"); } async list() { @@ -250,7 +254,7 @@ export default class DocsService { } } - Telemetry.capture("docs_pages_crawled", { + void Telemetry.capture("docs_pages_crawled", { count: processedPages, }); @@ -321,7 +325,7 @@ export default class DocsService { await this.delete(startUrl); } - const favicon = await this.fetchFavicon(siteIndexingConfig); + const favicon = await fetchFavicon(new URL(siteIndexingConfig.startUrl)); await this.add({ siteIndexingConfig, @@ -460,7 +464,7 @@ export default class DocsService { for (const doc of newDocs) { console.log(`Indexing new doc: ${doc.startUrl}`); - Telemetry.capture("add_docs_config", { url: doc.startUrl }); + void Telemetry.capture("add_docs_config", { url: doc.startUrl }); const generator = this.indexAndAdd(doc); while (!(await generator.next()).done) {} @@ -537,8 +541,9 @@ export default class DocsService { private async getLanceTableNameFromEmbeddingsProvider( isPreIndexedDoc: boolean, ) { - const embeddingsProvider = - await this.getEmbeddingsProvider(isPreIndexedDoc); + const embeddingsProvider = await this.getEmbeddingsProvider( + isPreIndexedDoc, + ); const embeddingsProviderId = this.removeInvalidLanceTableNameChars( embeddingsProvider.id, ); @@ -694,7 +699,12 @@ export default class DocsService { const siteEmbeddings = JSON.parse(data) as SiteIndexingResults; const startUrl = new URL(siteEmbeddings.url).toString(); - const favicon = await this.fetchFavicon(preIndexedDocs[startUrl]); + + const faviconUrl = preIndexedDocs[startUrl].faviconUrl; + const favicon = + typeof faviconUrl === "string" + ? await getFaviconBase64(faviconUrl) + : undefined; await this.add({ favicon, @@ -707,30 +717,6 @@ export default class DocsService { }); } - private async fetchFavicon(siteIndexingConfig: SiteIndexingConfig) { - const faviconUrl = - siteIndexingConfig.faviconUrl ?? - new URL("/favicon.ico", siteIndexingConfig.startUrl); - - try { - const response = await fetch(faviconUrl); - const arrayBuffer = await response.arrayBuffer(); - const base64 = btoa( - new Uint8Array(arrayBuffer).reduce( - (data, byte) => data + String.fromCharCode(byte), - "", - ), - ); - const mimeType = response.headers.get("content-type") || "image/x-icon"; - - return `data:${mimeType};base64,${base64}`; - } catch { - console.error(`Failed to fetch favicon: ${faviconUrl}`); - } - - return undefined; - } - private async shouldReindexDocsOnNewEmbeddingsProvider( curEmbeddingsProviderId: EmbeddingsProvider["id"], ): Promise { diff --git a/core/util/fetchFavicon.ts b/core/util/fetchFavicon.ts new file mode 100644 index 000000000..8b1c8616a --- /dev/null +++ b/core/util/fetchFavicon.ts @@ -0,0 +1,65 @@ +import { JSDOM } from "jsdom"; + +export async function findFaviconPath(url: URL): Promise { + const baseUrl = `${url.protocol}//${url.hostname}`; + + try { + const response = await fetch(baseUrl); + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`); + } + + const html = await response.text(); + const dom = new JSDOM(html); + const document = dom.window.document; + + // Look for favicon in tags + const linkTags = document.querySelectorAll('link[rel*="icon"]'); + + for (const link of linkTags) { + const href = link.getAttribute("href"); + if (href) { + return new URL(href, baseUrl).toString(); + } + } + } catch (error) { + console.debug(`Failed to fetch favicon for ${baseUrl}: ${error}`); + } + + console.debug(`Failed to find favicon for ${baseUrl}`); + return undefined; +} + +export async function getFaviconBase64( + faviconUrl: string, +): Promise { + try { + const response = await fetch(faviconUrl); + + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`); + } + + const arrayBuffer = await response.arrayBuffer(); + const base64 = btoa( + new Uint8Array(arrayBuffer).reduce( + (data, byte) => data + String.fromCharCode(byte), + "", + ), + ); + const mimeType = response.headers.get("content-type") || "image/x-icon"; + + return `data:${mimeType};base64,${base64}`; + } catch (error) { + console.debug(`Failed to fetch favicon from ${faviconUrl}: ${error}`); + return undefined; + } +} + +export async function fetchFavicon(url: URL): Promise { + const faviconPath = await findFaviconPath(url); + if (faviconPath) { + return getFaviconBase64(faviconPath); + } + return undefined; +} diff --git a/gui/src/components/mainInput/ContextItemsPeek.tsx b/gui/src/components/mainInput/ContextItemsPeek.tsx index 3d3200433..f7d0b2f3e 100644 --- a/gui/src/components/mainInput/ContextItemsPeek.tsx +++ b/gui/src/components/mainInput/ContextItemsPeek.tsx @@ -1,14 +1,9 @@ -import { ChevronDownIcon, ChevronUpIcon } from "@heroicons/react/24/outline"; +import { ChevronDownIcon, ChevronRightIcon } from "@heroicons/react/24/outline"; import { ContextItemWithId } from "core"; import { contextItemToRangeInFileWithContents } from "core/commands/util"; import React, { useContext } from "react"; import styled from "styled-components"; -import { - defaultBorderRadius, - lightGray, - vscBackground, - vscForeground, -} from ".."; +import { lightGray, vscBackground } from ".."; import { IdeMessengerContext } from "../../context/IdeMessenger"; import { getFontSize } from "../../util"; import FileIcon from "../FileIcon"; @@ -16,70 +11,26 @@ import SafeImg from "../SafeImg"; import { INSTRUCTIONS_BASE_ITEM } from "core/context/providers/utils"; import { getIconFromDropdownItem } from "./MentionList"; -const ContextItemDiv = styled.div` - cursor: pointer; - padding: 6px 10px 6px 6px; - margin-left: 4px; - margin-right: 12px; - display: flex; - align-items: center; - border-radius: ${defaultBorderRadius}; - font-size: ${getFontSize()}; - max-width: 100%; - overflow: hidden; - white-space: nowrap; - text-overflow: ellipsis; - - &:hover { - background-color: #fff1; - } -`; - -export const ContextItems = styled.span` - margin-left: 5px; - font-size: ${getFontSize() - 1}px; - color: ${lightGray}; - - &:hover { - text-decoration: underline; - } -`; - interface ContextItemsPeekProps { contextItems?: ContextItemWithId[]; } -function filterInstructionContextItem( - contextItems: ContextItemsPeekProps["contextItems"], -) { - return contextItems?.filter( - (ctxItem) => !ctxItem.name.includes(INSTRUCTIONS_BASE_ITEM.name), - ); +interface ContextItemsPeekItemProps { + contextItem: ContextItemWithId; } -const ContextItemsPeek = (props: ContextItemsPeekProps) => { +function ContextItemsPeekItem({ contextItem }: ContextItemsPeekItemProps) { const ideMessenger = useContext(IdeMessengerContext); - const [open, setOpen] = React.useState(false); + function openContextItem() { + const { uri, name, description, content } = contextItem; - const ctxItems = filterInstructionContextItem(props.contextItems); + if (uri?.type === "url") { + window.open(description, "_blank"); + } else if (uri) { + const isRangeInFile = name.includes(" (") && name.endsWith(")"); - if (!ctxItems || ctxItems.length === 0) { - return null; - } - - const contextItemsText = `${ctxItems.length} context ${ - ctxItems.length > 1 ? "items" : "item" - }`; - - function openContextItem(contextItem: ContextItemWithId) { - if (contextItem.description.startsWith("http")) { - window.open(contextItem.description, "_blank"); - } else if ( - contextItem.description.startsWith("/") || - contextItem.description.startsWith("\\") - ) { - if (contextItem.name.includes(" (") && contextItem.name.endsWith(")")) { + if (isRangeInFile) { const rif = contextItemToRangeInFileWithContents(contextItem); ideMessenger.ide.showLines( rif.filepath, @@ -87,23 +38,23 @@ const ContextItemsPeek = (props: ContextItemsPeekProps) => { rif.range.end.line, ); } else { - ideMessenger.ide.openFile(contextItem.description); + ideMessenger.ide.openFile(description); } } else { - ideMessenger.ide.showVirtualFile(contextItem.name, contextItem.content); + ideMessenger.ide.showVirtualFile(name, content); } } - const getContextItemIcon = (contextItem: ContextItemWithId) => { - const dimmensions = "1.4em"; + function getContextItemIcon() { + const dimensions = "18px"; if (contextItem.icon) { return ( ); @@ -114,13 +65,16 @@ const ContextItemsPeek = (props: ContextItemsPeekProps) => { if (shouldShowFileIcon) { return ( - +
+ +
); } @@ -131,79 +85,99 @@ const ContextItemsPeek = (props: ContextItemsPeekProps) => { return ( ); - }; + } return (
+
+ {getContextItemIcon()} +
+
+ {contextItem.name} +
+
+ {contextItem.description} +
+
+
+
+ ); +} + +function ContextItemsPeek({ contextItems }: ContextItemsPeekProps) { + const [open, setOpen] = React.useState(false); + + const ctxItems = contextItems?.filter( + (ctxItem) => !ctxItem.name.includes(INSTRUCTIONS_BASE_ITEM.name), + ); + + if (!ctxItems || ctxItems.length === 0) { + return null; + } + + const contextItemsText = `${ctxItems.length} context ${ + ctxItems.length > 1 ? "items" : "item" + }`; + + return ( +
setOpen((prev) => !prev)} > - {open ? ( - + - ) : ( + /> - )} - {contextItemsText} + /> +
+ + {contextItemsText} +
- {open && ( -
- {ctxItems?.map((contextItem, idx) => { - const contextItemContent = ( - openContextItem(contextItem)}> - {getContextItemIcon(contextItem)} - {contextItem.name} - - ); - - return contextItem.description.startsWith("http") ? ( - - {contextItemContent} - - ) : ( - {contextItemContent} - ); - })} -
- )} +
+ {ctxItems.map((contextItem, idx) => ( + + ))} +
); -}; +} export default ContextItemsPeek; diff --git a/gui/src/components/mainInput/InputToolbar.tsx b/gui/src/components/mainInput/InputToolbar.tsx index 367741b27..e8bbd080a 100644 --- a/gui/src/components/mainInput/InputToolbar.tsx +++ b/gui/src/components/mainInput/InputToolbar.tsx @@ -1,6 +1,6 @@ import { + AtSymbolIcon, PhotoIcon as OutlinePhotoIcon, - PlusIcon, } from "@heroicons/react/24/outline"; import { PhotoIcon as SolidPhotoIcon } from "@heroicons/react/24/solid"; import { InputModifiers } from "core"; @@ -36,64 +36,47 @@ const StyledDiv = styled.div<{ isHidden: boolean }>` cursor: ${(props) => (props.isHidden ? "default" : "text")}; opacity: ${(props) => (props.isHidden ? 0 : 1)}; pointer-events: ${(props) => (props.isHidden ? "none" : "auto")}; - user-select: none; & > * { flex: 0 0 auto; } +`; - /* Hide the "Use codebase" span first */ - @media (max-width: 450px) { - & > span:last-child > span:nth-last-child(2) { - display: none; - } +const HoverItem = styled.span<{ isActive?: boolean }>` + padding: 0 4px; + padding-top: 2px; + padding-bottom: 2px; + cursor: pointer; + transition: color 200ms; + + &:hover { + color: #d1d5db; } `; -const SecondToDisappearContainer = styled.span` - display: flex; - align-items: center; - - @media (max-width: 350px) { - display: none; - } -`; - -const StyledSpan = styled.span` - font-size: ${() => `${getFontSize() - 2}px`}; - color: ${lightGray}; -`; - -const EnterButton = styled.div<{ offFocus: boolean }>` +const EnterButton = styled.div` padding: 2px 4px; display: flex; align-items: center; - - background-color: ${(props) => - props.offFocus ? undefined : lightGray + "33"}; + background-color: ${lightGray}33; border-radius: ${defaultBorderRadius}; color: ${vscForeground}; + cursor: pointer; &:hover { background-color: ${vscBadgeBackground}; color: ${vscBadgeForeground}; } - - cursor: pointer; `; interface InputToolbarProps { onEnter?: (modifiers: InputModifiers) => void; - usingCodebase?: boolean; onAddContextItem?: () => void; - onClick?: () => void; - onImageFileSelected?: (file: File) => void; - hidden?: boolean; - showNoContext: boolean; + activeKey: string | null; } function InputToolbar(props: InputToolbarProps) { @@ -103,6 +86,8 @@ function InputToolbar(props: InputToolbarProps) { const defaultModel = useSelector(defaultModelSelector); const useActiveFile = useSelector(selectUseActiveFile); + console.log(props.activeKey); + return ( <> - - - - - { - props.onAddContextItem(); - }} - className="hover:underline cursor-pointer" +
+
+ +
+
+ - Add Context{" "} - + {defaultModel && modelSupportsImages( defaultModel.provider, @@ -149,18 +133,14 @@ function InputToolbar(props: InputToolbarProps) { /> {fileSelectHovered ? ( { fileInputRef.current?.click(); }} /> ) : ( { fileInputRef.current?.click(); }} @@ -168,59 +148,51 @@ function InputToolbar(props: InputToolbarProps) { )} )} - - - - - {props.showNoContext ? ( - - {getAltKeyLabel()} ⏎{" "} - {useActiveFile ? "No context" : "Use active file"} - - ) : ( - { - props.onEnter({ - useCodebase: true, - noContext: !useActiveFile, - }); - }} - className={"hover:underline cursor-pointer float-right"} - > - {getMetaKeyLabel()} ⏎ Use @codebase - - )} -
- { - props.onEnter({ - useCodebase: isMetaEquivalentKeyPressed(e), - noContext: useActiveFile ? e.altKey : !e.altKey, - }); - }} - > - ⏎ Enter -
-
+
+ +
+
+ {props.activeKey === "Alt" ? ( + + {`${getAltKeyLabel()}⏎ + ${useActiveFile ? "No active file" : "Active file"}`} + + ) : ( + + props.onEnter({ + useCodebase: true, + noContext: !useActiveFile, + }) + } + > + + {" "} + {getMetaKeyLabel()}⏎ @codebase + + @codebase + + )} +
+ + { + props.onEnter({ + useCodebase: isMetaEquivalentKeyPressed(e), + noContext: useActiveFile ? e.altKey : !e.altKey, + }); + }} + > + ⏎ Enter + ⏎ + +
); diff --git a/gui/src/components/mainInput/TipTapEditor.tsx b/gui/src/components/mainInput/TipTapEditor.tsx index a57d19bda..21f0b3923 100644 --- a/gui/src/components/mainInput/TipTapEditor.tsx +++ b/gui/src/components/mainInput/TipTapEditor.tsx @@ -57,6 +57,7 @@ import { getSlashCommandDropdownOptions, } from "./getSuggestion"; import { ComboBoxItem } from "./types"; +import { v4 } from "uuid"; const InputBoxDiv = styled.div` resize: none; @@ -729,7 +730,11 @@ function TipTapEditor(props: TipTapEditorProps) { description: `${relativePath} ${rangeStr}`, id: { providerTitle: "code", - itemId: rif.filepath, + itemId: v4(), + }, + uri: { + type: "file", + value: rif.filepath, }, }; @@ -810,19 +815,15 @@ function TipTapEditor(props: TipTapEditorProps) { }; }, []); - const [optionKeyHeld, setOptionKeyHeld] = useState(false); + const [activeKey, setActiveKey] = useState(null); return ( { - if (e.key === "Alt") { - setOptionKeyHeld(true); - } + setActiveKey(e.key); }} onKeyUp={(e) => { - if (e.key === "Alt") { - setOptionKeyHeld(false); - } + setActiveKey(null); }} className="cursor-text" onClick={() => { @@ -874,7 +875,7 @@ function TipTapEditor(props: TipTapEditorProps) { }} />