diff --git a/core/index.d.ts b/core/index.d.ts index d3ff2a4b8..05e0d90a6 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -871,10 +871,14 @@ interface QuickActionConfig { sendToChat: boolean; } +export type DefaultContextProvider = ContextProviderWithParams & { + query?: string; +}; + interface ExperimentalConfig { contextMenuPrompts?: ContextMenuConfig; modelRoles?: ModelRoles; - defaultContext?: "activeFile"[]; + defaultContext?: DefaultContextProvider[]; promptPath?: string; /** diff --git a/docs/static/schemas/config.json b/docs/static/schemas/config.json index 180454880..44a908810 100644 --- a/docs/static/schemas/config.json +++ b/docs/static/schemas/config.json @@ -2374,7 +2374,19 @@ "defaultContext": { "type": "array", "items": { - "enum": ["activeFile"] + "allOf": [ + { + "$ref": "#/definitions/ContextProviderWithParams" + }, + { + "properties": { + "query": { + "type": "string", + "description": "Required for certain context providers, like 'url' in order to specify the input, or which of the dropdown items to select." + } + } + } + ] } }, "modelRoles": { diff --git a/extensions/intellij/src/main/resources/config_schema.json b/extensions/intellij/src/main/resources/config_schema.json index 180454880..44a908810 100644 --- a/extensions/intellij/src/main/resources/config_schema.json +++ b/extensions/intellij/src/main/resources/config_schema.json @@ -2374,7 +2374,19 @@ "defaultContext": { "type": "array", "items": { - "enum": ["activeFile"] + "allOf": [ + { + "$ref": "#/definitions/ContextProviderWithParams" + }, + { + "properties": { + "query": { + "type": "string", + "description": "Required for certain context providers, like 'url' in order to specify the input, or which of the dropdown items to select." + } + } + } + ] } }, "modelRoles": { diff --git a/extensions/vscode/config_schema.json b/extensions/vscode/config_schema.json index 180454880..44a908810 100644 --- a/extensions/vscode/config_schema.json +++ b/extensions/vscode/config_schema.json @@ -2374,7 +2374,19 @@ "defaultContext": { "type": "array", "items": { - "enum": ["activeFile"] + "allOf": [ + { + "$ref": "#/definitions/ContextProviderWithParams" + }, + { + "properties": { + "query": { + "type": "string", + "description": "Required for certain context providers, like 'url' in order to specify the input, or which of the dropdown items to select." + } + } + } + ] } }, "modelRoles": { diff --git a/extensions/vscode/continue_rc_schema.json b/extensions/vscode/continue_rc_schema.json index fcbba3140..d6c797596 100644 --- a/extensions/vscode/continue_rc_schema.json +++ b/extensions/vscode/continue_rc_schema.json @@ -2669,8 +2669,18 @@ "defaultContext": { "type": "array", "items": { - "enum": [ - "activeFile" + "allOf": [ + { + "$ref": "#/definitions/ContextProviderWithParams" + }, + { + "properties": { + "query": { + "type": "string", + "description": "Required for certain context providers, like 'url' in order to specify the input, or which of the dropdown items to select." + } + } + } ] } }, diff --git a/gui/src/components/mainInput/resolveInput.ts b/gui/src/components/mainInput/resolveInput.ts index 955ea6f4d..7d26faf25 100644 --- a/gui/src/components/mainInput/resolveInput.ts +++ b/gui/src/components/mainInput/resolveInput.ts @@ -1,6 +1,7 @@ import { JSONContent } from "@tiptap/react"; import { ContextItemWithId, + DefaultContextProvider, InputModifiers, MessageContent, MessagePart, @@ -27,6 +28,7 @@ async function resolveEditorContent( editorState: JSONContent, modifiers: InputModifiers, ideMessenger: IIdeMessenger, + defaultContextProviders: DefaultContextProvider[], ): Promise<[ContextItemWithId[], RangeInFile[], MessageContent]> { let parts: MessagePart[] = []; let contextItemAttrs: MentionAttrs[] = []; @@ -131,6 +133,20 @@ async function resolveEditorContent( } } + // Include default context providers + const defaultContextItems = await Promise.all( + defaultContextProviders.map(async (provider) => { + const items = await ideMessenger.request("context/getContextItems", { + name: provider.name, + query: provider.query ?? "", + fullInput: stripImages(parts), + selectedCode, + }); + return items; + }), + ); + contextItems.push(...defaultContextItems.flat()); + if (contextItemsText !== "") { contextItemsText += "\n"; } diff --git a/gui/src/hooks/useChatHandler.ts b/gui/src/hooks/useChatHandler.ts index 94e372d3f..035e8322c 100644 --- a/gui/src/hooks/useChatHandler.ts +++ b/gui/src/hooks/useChatHandler.ts @@ -37,6 +37,9 @@ function useChatHandler(dispatch: Dispatch, ideMessenger: IIdeMessenger) { const posthog = usePostHog(); const defaultModel = useSelector(defaultModelSelector); + const defaultContextProviders = useSelector( + (store: RootState) => store.state.config.experimental?.defaultContext ?? [], + ); const slashCommands = useSelector( (store: RootState) => store.state.config.slashCommands || [], @@ -181,11 +184,11 @@ function useChatHandler(dispatch: Dispatch, ideMessenger: IIdeMessenger) { editorState, modifiers, ideMessenger, + defaultContextProviders, ); - dispatch(addContextItems(contextItems)); // Automatically use currently open file - if (!modifiers.noContext && (history.length === 0 || index === 0)) { + if (!modifiers.noContext) { const usingFreeTrial = defaultModel?.provider === "free-trial"; const currentFilePath = await ideMessenger.ide.getCurrentFile(); @@ -212,6 +215,7 @@ function useChatHandler(dispatch: Dispatch, ideMessenger: IIdeMessenger) { }); } } + dispatch(addContextItems(contextItems)); const message: ChatMessage = { role: "user",