support for all context providers in defaultContext
This commit is contained in:
parent
5b2a64f6a1
commit
10e860833a
7 changed files with 78 additions and 8 deletions
6
core/index.d.ts
vendored
6
core/index.d.ts
vendored
|
|
@ -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;
|
||||
|
||||
/**
|
||||
|
|
|
|||
14
docs/static/schemas/config.json
vendored
14
docs/static/schemas/config.json
vendored
|
|
@ -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": {
|
||||
|
|
|
|||
|
|
@ -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": {
|
||||
|
|
|
|||
|
|
@ -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": {
|
||||
|
|
|
|||
|
|
@ -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."
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -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";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue