Skip to content

Commit f4f9b31

Browse files
authored
Merge pull request #7224 from continuedev/dallin/context-defaults
feat: update default-included context providers
2 parents 1674c2a + 625ec8c commit f4f9b31

File tree

13 files changed

+757
-214
lines changed

13 files changed

+757
-214
lines changed

binary/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"pkg": "^5.8.1",
4040
"rimraf": "^5.0.7",
4141
"ts-jest": "^29.1.4",
42-
"typescript": "^5.3.3"
42+
"typescript": "^5.6.3"
4343
},
4444
"dependencies": {
4545
"@octokit/rest": "^20.0.2",

core/config/default.ts

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,8 @@
11
import { ConfigYaml } from "@continuedev/config-yaml";
22

3-
export const defaultContextProvidersVsCode: NonNullable<
4-
ConfigYaml["context"]
5-
>[number][] = [
6-
{ provider: "code" },
7-
{ provider: "docs" },
8-
{ provider: "diff" },
9-
{ provider: "terminal" },
10-
{ provider: "problems" },
11-
{ provider: "folder" },
12-
{ provider: "codebase" },
13-
];
14-
15-
export const defaultContextProvidersJetBrains: NonNullable<
16-
ConfigYaml["context"]
17-
>[number][] = [
18-
{ provider: "diff" },
19-
{ provider: "folder" },
20-
{ provider: "codebase" },
21-
];
22-
233
export const defaultConfig: ConfigYaml = {
244
name: "Local Agent",
255
version: "1.0.0",
266
schema: "v1",
277
models: [],
28-
context: defaultContextProvidersVsCode,
29-
};
30-
31-
export const defaultConfigJetBrains: ConfigYaml = {
32-
name: "Local Agent",
33-
version: "1.0.0",
34-
schema: "v1",
35-
models: [],
36-
context: defaultContextProvidersJetBrains,
378
};

core/config/load.ts

Lines changed: 19 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import {
1919
ContinueRcJson,
2020
CustomContextProvider,
2121
EmbeddingsProviderDescription,
22-
IContextProvider,
2322
IDE,
2423
IdeInfo,
2524
IdeSettings,
@@ -36,10 +35,6 @@ import { getLegacyBuiltInSlashCommandFromDescription } from "../commands/slash/b
3635
import { convertCustomCommandToSlashCommand } from "../commands/slash/customSlashCommand";
3736
import { slashCommandFromPromptFile } from "../commands/slash/promptFileSlashCommand";
3837
import { MCPManagerSingleton } from "../context/mcp/MCPManagerSingleton";
39-
import ContinueProxyContextProvider from "../context/providers/ContinueProxyContextProvider";
40-
import CustomContextProviderClass from "../context/providers/CustomContextProvider";
41-
import FileContextProvider from "../context/providers/FileContextProvider";
42-
import { contextProviderClassFromName } from "../context/providers/index";
4338
import { useHub } from "../control-plane/env";
4439
import { BaseLLM } from "../llm";
4540
import { LLMClasses, llmFromDescription } from "../llm/llms";
@@ -62,9 +57,11 @@ import {
6257
} from "../util/paths";
6358
import { localPathToUri } from "../util/pathToUri";
6459

60+
import CustomContextProviderClass from "../context/providers/CustomContextProvider";
6561
import { getToolsForIde } from "../tools";
6662
import { resolveRelativePathInDir } from "../util/ideUtils";
6763
import { getWorkspaceRcConfigs } from "./json/loadRcConfigs";
64+
import { loadConfigContextProviders } from "./loadContextProviders";
6865
import { modifyAnyConfigWithSharedConfig } from "./sharedConfig";
6966
import {
7067
getModelByRole,
@@ -229,7 +226,7 @@ function applyRequestOptionsToModels(
229226
export function isContextProviderWithParams(
230227
contextProvider: CustomContextProvider | ContextProviderWithParams,
231228
): contextProvider is ContextProviderWithParams {
232-
return (contextProvider as ContextProviderWithParams).name !== undefined;
229+
return "name" in contextProvider && !!contextProvider.name;
233230
}
234231

235232
/** Only difference between intermediate and final configs is the `models` array */
@@ -386,50 +383,25 @@ async function intermediateToFinalConfig({
386383

387384
applyRequestOptionsToModels(tabAutocompleteModels, config);
388385

389-
// These context providers are always included, regardless of what, if anything,
390-
// the user has configured in config.json
391-
392-
const codebaseContextParams =
393-
(
394-
(config.contextProviders || [])
395-
.filter(isContextProviderWithParams)
396-
.find((cp) => cp.name === "codebase") as
397-
| ContextProviderWithParams
398-
| undefined
399-
)?.params || {};
400-
401-
const DEFAULT_CONTEXT_PROVIDERS = [new FileContextProvider({})];
402-
403-
const DEFAULT_CONTEXT_PROVIDERS_TITLES = DEFAULT_CONTEXT_PROVIDERS.map(
404-
({ description: { title } }) => title,
405-
);
406-
407-
// Context providers
408-
const contextProviders: IContextProvider[] = DEFAULT_CONTEXT_PROVIDERS;
409-
410-
for (const provider of config.contextProviders || []) {
411-
if (isContextProviderWithParams(provider)) {
412-
const cls = contextProviderClassFromName(provider.name) as any;
413-
if (!cls) {
414-
if (!DEFAULT_CONTEXT_PROVIDERS_TITLES.includes(provider.name)) {
415-
console.warn(`Unknown context provider ${provider.name}`);
416-
}
417-
418-
continue;
419-
}
420-
const instance: IContextProvider = new cls(provider.params);
421-
422-
// Handle continue-proxy
423-
if (instance.description.title === "continue-proxy") {
424-
(instance as ContinueProxyContextProvider).workOsAccessToken =
425-
workOsAccessToken;
426-
}
386+
// Load context providers
387+
const { providers: contextProviders, errors: contextErrors } =
388+
loadConfigContextProviders(
389+
config.contextProviders
390+
?.filter((cp) => isContextProviderWithParams(cp))
391+
.map((cp) => ({
392+
provider: (cp as ContextProviderWithParams).name,
393+
params: (cp as ContextProviderWithParams).params,
394+
})),
395+
!!config.docs?.length,
396+
ideInfo.ideType,
397+
);
427398

428-
contextProviders.push(instance);
429-
} else {
430-
contextProviders.push(new CustomContextProviderClass(provider));
399+
for (const cp of config.contextProviders ?? []) {
400+
if (!isContextProviderWithParams(cp)) {
401+
contextProviders.push(new CustomContextProviderClass(cp));
431402
}
432403
}
404+
errors.push(...contextErrors);
433405

434406
// Embeddings Provider
435407
function getEmbeddingsILLM(
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import {
2+
AssistantUnrolledNonNullable,
3+
ConfigValidationError,
4+
} from "@continuedev/config-yaml";
5+
import { IContextProvider, IdeType } from "..";
6+
import { contextProviderClassFromName } from "../context/providers";
7+
import CurrentFileContextProvider from "../context/providers/CurrentFileContextProvider";
8+
import DiffContextProvider from "../context/providers/DiffContextProvider";
9+
import DocsContextProvider from "../context/providers/DocsContextProvider";
10+
import FileContextProvider from "../context/providers/FileContextProvider";
11+
import ProblemsContextProvider from "../context/providers/ProblemsContextProvider";
12+
import RulesContextProvider from "../context/providers/RulesContextProvider";
13+
import TerminalContextProvider from "../context/providers/TerminalContextProvider";
14+
15+
/*
16+
Loads context providers based on configuration
17+
- default providers will always be loaded, using config params if present
18+
- other providers will be loaded if configured
19+
20+
NOTE the MCPContextProvider is added in doLoadConfig if any resources are present
21+
*/
22+
export function loadConfigContextProviders(
23+
configContext: AssistantUnrolledNonNullable["context"],
24+
hasDocs: boolean,
25+
ideType: IdeType,
26+
): {
27+
providers: IContextProvider[];
28+
errors: ConfigValidationError[];
29+
} {
30+
const providers: IContextProvider[] = [];
31+
const errors: ConfigValidationError[] = [];
32+
// Add from config
33+
if (configContext) {
34+
for (const config of configContext) {
35+
const cls = contextProviderClassFromName(config.provider) as any;
36+
if (!cls) {
37+
errors.push({
38+
fatal: false,
39+
message: `Unknown context provider ${config.provider}`,
40+
});
41+
continue;
42+
}
43+
providers.push(
44+
new cls({
45+
name: config.name,
46+
...config.params,
47+
}),
48+
);
49+
}
50+
}
51+
52+
// Add from defaults if not found in config
53+
const defaultProviders: IContextProvider[] = [
54+
new FileContextProvider({}),
55+
new CurrentFileContextProvider({}),
56+
new DiffContextProvider({}),
57+
new TerminalContextProvider({}),
58+
new ProblemsContextProvider({}),
59+
new RulesContextProvider({}),
60+
];
61+
62+
for (const defaultProvider of defaultProviders) {
63+
if (
64+
!providers.find(
65+
(p) => p.description.title === defaultProvider.description.title,
66+
)
67+
) {
68+
providers.push(defaultProvider);
69+
}
70+
}
71+
72+
if (hasDocs && !providers?.some((cp) => cp.description.title === "docs")) {
73+
providers.push(new DocsContextProvider({}));
74+
}
75+
76+
// @problems and @terminal are not supported in jetbrains
77+
const filteredProviders = providers.filter((pv) => {
78+
if (ideType === "jetbrains") {
79+
return (
80+
pv.description.title !== TerminalContextProvider.description.title &&
81+
pv.description.title !== ProblemsContextProvider.description.title
82+
);
83+
}
84+
return true;
85+
});
86+
87+
return {
88+
providers: filteredProviders,
89+
errors,
90+
};
91+
}

0 commit comments

Comments
 (0)