* docs: add docs and schema for "OS" provider (#1536) * ignore .env * fix(gui): ctx rendering w/ renderInlineAs: "" (#1541) * ✨ use and cache imports for autocomplete (#1456) * ✨ use and cache imports for autocomplete * fix tsc * fix codeqwen autocomplete leading space * add voyage rerank-1 * feat: `--noEmit` for tsc checks in CI (#1559) * docs: update CustomContextProvider docs (#1557) * add stop tokens to qwen prompt * update docs to reflect 3.5 sonnet being best * docs: comment out unused providers (#1561) * import Handlebars * feat: toast notification for config updates (#1560) * feat: toast notification for config updates * feat: only trigger toast on config.json save * displayRawMarkdown option * feat: open pane on install (#1564) * feat: open pane on activation * comment out testing code * update to reflect 16 stop words limit for deepseek * feat: only trigger config update toast in vscode (#1571) * docs(prompt-files): fix typos + clarify (#1575) * doc: prompt file typo + clarifications * fix: add back correct docs * chore: add telemetry for pageviews (#1576) * feat: update onboarding w/ embeddings model (#1570) * chore(gui): remove unused pages * feat: add embeddings step * feat: update styles * feat: copy button updates * fix: correct pull command for embed model * fix: remove commented code * fix: remove commented code * feat: simplify copy btn props * chore: rename onboarding selection event * feat: add provider config * fix: undo msg name * remove dead code * fix: invalid mode check * fix: remove testing logic * docs(telemetry): add pageviews to tracking list (#1581) * Add reranker configuration options to codebase embedding docs (#1584) - Introduce reranker concept - List available reranker options - Provide configuration instructions - Update keywords to include "reranker" * chore: update pr template with screenshots (#1590) * Refactor ConfirmationDialog to use SecondaryButton for cancel action (#1586) * Added instructions for running docs server locally (#1578) - Added NPM script method - Added VS Code task method - Update contributing guidelines * Update branch policy (#1577) - Change PR target to `dev` branch - Update `CONTRIBUTING.md` instructions * Consolidate example configurations into the main configuration guide (#1579) - Moved examples to configuration.md - Deleted the separate examples.md file - Updated sidebar order and links - Improved readability and structure in configuration.md * fix: fullscreen gui retains context when hidden, fixed fullscreen focusing (#1582) * Update completionProvider.ts (warning tab-autocomplete models) (#1566) * feat: enhanced IndexingProgressBar with blinking dot feature - Integrated BlinkingDot component - Added STATUS_COLORS for various states - Replaced CircleDiv with BlinkingDot in UI - Updated status messages and layout * small UI tweaks * feat(gui): enhance ModelCard, ModelProviderTag, and Toggle components (#1595) - add styling and adjustments to ModelCard - update ModelProviderTag font size - remove box shadow from Toggle component - tweak icon styles in ModelCard - improve alignment and spacing * media query * feat: add best experience onboarding * fix: file rename * stop movement on button hover by keeping same border thickness * fix mistake in setting cursor: pointer * fix when free trial option is shown * Support Node.js versions below 20 for streaming response handling (#1591) - Add fallback for Node < 20 - Implement toAsyncIterable for streaming - Use TextDecoder for manual decoding - Maintain existing streaming for Node 20+ * small fixes * feat: add free trial card to onboarding (#1600) * feat: add free trial card to onboarding * add import * fix hasPassedFTL * fix /edit cancellation from UI * feat: add `applyCodeBlock` experimental prop (#1601) * feat: add new model styling improvements (#1609) * feat: add new model styling improvements * better gap size * feat: update bug_report.yml (#1610) * chore: update bug_report.yml * typo fix * feat: add labels to "Add docs" dialog (#1612) * feat: add labels to "Add docs" dialog * remove autofocus * don't double load config * small fixes * speed up directory traversal, and use correct native path module * option not to show config update toast * merge air-gapped and recommended setup pages * chore: add telemetry for full screen toggle (#1618) * Fix headings in codebase-embeddings.md (#1617) * mention jetbrains * docs: update changie (#1619) * feat: updated changie config * hide toc and autogenerate * Update changelog.mdx * link to deeper explanation of embeddings models * ensure target="_blank" for all links in sidebar * fix gif links in intellij README.md * don't require rust in dependency installation * chore: fix padding on gh button (#1620) * chore: adjust button padding * Update tasks.json * escape colons in diff path * smoother lancedb indexing reporting * smooth progress updates for indexing * fix tsc err * rerank-lite-1 * remove doccs * basic tests for VS Code extension * improved testing of VS Code extension * docs: add docs and schema for "OS" provider (#1536) * ignore .env * 🚑 fix constant warnings when onboarding with Ollama * ✨ use and cache imports for autocomplete (#1456) * ✨ use and cache imports for autocomplete * fix tsc * team analytics * apply control plane settings * workos auth * ide protocol get session info * UI for auth * profile switching * small fixes * updates * refresh tokens * updates * fix tsc errs * model select in toolbar to make room for profile selector * prod client id * link to prod URL * internal beta option * profiles change listener --------- Co-authored-by: Patrick Erichsen <patrick.a.erichsen@gmail.com> Co-authored-by: Priyash <38959321+priyashpatil@users.noreply.github.com> Co-authored-by: Jonah Wagner <jonahwagner231@gmail.com> Co-authored-by: YohannZe <99359799+YohannZe@users.noreply.github.com> Co-authored-by: Dan Dascalescu <ddascalescu+github@gmail.com>
266 lines
8 KiB
TypeScript
266 lines
8 KiB
TypeScript
import { ControlPlaneClient } from "../control-plane/client.js";
|
|
import {
|
|
BrowserSerializedContinueConfig,
|
|
ContinueConfig,
|
|
IContextProvider,
|
|
IDE,
|
|
IdeSettings,
|
|
ILLM,
|
|
} from "../index.js";
|
|
import { GlobalContext } from "../util/GlobalContext.js";
|
|
import { finalToBrowserConfig } from "./load.js";
|
|
import ControlPlaneProfileLoader from "./profile/ControlPlaneProfileLoader.js";
|
|
import { IProfileLoader } from "./profile/IProfileLoader.js";
|
|
import LocalProfileLoader from "./profile/LocalProfileLoader.js";
|
|
|
|
export interface ProfileDescription {
|
|
title: string;
|
|
id: string;
|
|
}
|
|
|
|
// Separately manages saving/reloading each profile
|
|
class ProfileLifecycleManager {
|
|
private savedConfig: ContinueConfig | undefined;
|
|
private savedBrowserConfig?: BrowserSerializedContinueConfig;
|
|
private pendingConfigPromise?: Promise<ContinueConfig>;
|
|
|
|
constructor(private readonly profileLoader: IProfileLoader) {}
|
|
|
|
get profileId() {
|
|
return this.profileLoader.profileId;
|
|
}
|
|
|
|
get profileTitle() {
|
|
return this.profileLoader.profileTitle;
|
|
}
|
|
|
|
get profileDescription(): ProfileDescription {
|
|
return {
|
|
title: this.profileTitle,
|
|
id: this.profileId,
|
|
};
|
|
}
|
|
|
|
clearConfig() {
|
|
this.savedConfig = undefined;
|
|
this.savedBrowserConfig = undefined;
|
|
this.pendingConfigPromise = undefined;
|
|
}
|
|
|
|
// Clear saved config and reload
|
|
reloadConfig(): Promise<ContinueConfig> {
|
|
this.savedConfig = undefined;
|
|
this.savedBrowserConfig = undefined;
|
|
this.pendingConfigPromise = undefined;
|
|
|
|
return this.profileLoader.doLoadConfig();
|
|
}
|
|
|
|
async loadConfig(
|
|
additionalContextProviders: IContextProvider[],
|
|
): Promise<ContinueConfig> {
|
|
// If we already have a config, return it
|
|
if (this.savedConfig) {
|
|
return this.savedConfig;
|
|
} else if (this.pendingConfigPromise) {
|
|
return this.pendingConfigPromise;
|
|
}
|
|
|
|
// Set pending config promise
|
|
this.pendingConfigPromise = new Promise(async (resolve, reject) => {
|
|
const newConfig = await this.profileLoader.doLoadConfig();
|
|
|
|
// Add registered context providers
|
|
newConfig.contextProviders = (newConfig.contextProviders ?? []).concat(
|
|
additionalContextProviders,
|
|
);
|
|
|
|
this.savedConfig = newConfig;
|
|
resolve(newConfig);
|
|
});
|
|
|
|
// Wait for the config promise to resolve
|
|
this.savedConfig = await this.pendingConfigPromise;
|
|
this.pendingConfigPromise = undefined;
|
|
return this.savedConfig;
|
|
}
|
|
|
|
async getSerializedConfig(
|
|
additionalContextProviders: IContextProvider[],
|
|
): Promise<BrowserSerializedContinueConfig> {
|
|
if (!this.savedBrowserConfig) {
|
|
const continueConfig = await this.loadConfig(additionalContextProviders);
|
|
this.savedBrowserConfig = finalToBrowserConfig(continueConfig);
|
|
}
|
|
return this.savedBrowserConfig;
|
|
}
|
|
}
|
|
|
|
export class ConfigHandler {
|
|
private readonly globalContext = new GlobalContext();
|
|
private additionalContextProviders: IContextProvider[] = [];
|
|
private profiles: ProfileLifecycleManager[];
|
|
private selectedProfileId: string;
|
|
|
|
// This will be the local profile
|
|
private get fallbackProfile() {
|
|
return this.profiles[0];
|
|
}
|
|
|
|
get currentProfile() {
|
|
return (
|
|
this.profiles.find((p) => p.profileId === this.selectedProfileId) ??
|
|
this.fallbackProfile
|
|
);
|
|
}
|
|
|
|
get inactiveProfiles() {
|
|
return this.profiles.filter((p) => p.profileId !== this.selectedProfileId);
|
|
}
|
|
|
|
constructor(
|
|
private readonly ide: IDE,
|
|
private ideSettingsPromise: Promise<IdeSettings>,
|
|
private readonly writeLog: (text: string) => Promise<void>,
|
|
private readonly controlPlaneClient: ControlPlaneClient,
|
|
) {
|
|
this.ide = ide;
|
|
this.ideSettingsPromise = ideSettingsPromise;
|
|
this.writeLog = writeLog;
|
|
|
|
// Set local profile as default
|
|
const localProfileLoader = new LocalProfileLoader(
|
|
ide,
|
|
ideSettingsPromise,
|
|
writeLog,
|
|
);
|
|
this.profiles = [new ProfileLifecycleManager(localProfileLoader)];
|
|
this.selectedProfileId = localProfileLoader.profileId;
|
|
|
|
// Always load local profile immediately in case control plane doesn't load
|
|
try {
|
|
this.loadConfig();
|
|
} catch (e) {
|
|
console.error("Failed to load config: ", e);
|
|
}
|
|
|
|
// Load control plane profiles
|
|
// TODO
|
|
// Get the profiles and create their lifecycle managers
|
|
this.controlPlaneClient.listWorkspaces().then(async (workspaces) => {
|
|
workspaces.forEach((workspace) => {
|
|
const profileLoader = new ControlPlaneProfileLoader(
|
|
workspace.id,
|
|
workspace.name,
|
|
this.controlPlaneClient,
|
|
ide,
|
|
ideSettingsPromise,
|
|
writeLog,
|
|
this.reloadConfig.bind(this),
|
|
);
|
|
this.profiles.push(new ProfileLifecycleManager(profileLoader));
|
|
});
|
|
|
|
this.notifyProfileListeners(
|
|
this.profiles.map((profile) => profile.profileDescription),
|
|
);
|
|
|
|
// Check the last selected workspace, and reload if it isn't local
|
|
const workspaceId = await this.getWorkspaceId();
|
|
const lastSelectedWorkspaceIds =
|
|
this.globalContext.get("lastSelectedProfileForWorkspace") ?? {};
|
|
const selectedWorkspaceId = lastSelectedWorkspaceIds[workspaceId];
|
|
if (selectedWorkspaceId) {
|
|
this.selectedProfileId = selectedWorkspaceId;
|
|
this.loadConfig();
|
|
} else {
|
|
// Otherwise we stick with local profile, and record choice
|
|
lastSelectedWorkspaceIds[workspaceId] = this.selectedProfileId;
|
|
this.globalContext.update(
|
|
"lastSelectedProfileForWorkspace",
|
|
lastSelectedWorkspaceIds,
|
|
);
|
|
}
|
|
});
|
|
}
|
|
|
|
async setSelectedProfile(profileId: string) {
|
|
this.selectedProfileId = profileId;
|
|
const newConfig = await this.loadConfig();
|
|
this.notifyConfigListerners(newConfig);
|
|
}
|
|
|
|
// A unique ID for the current workspace, built from folder names
|
|
private async getWorkspaceId(): Promise<string> {
|
|
const dirs = await this.ide.getWorkspaceDirs();
|
|
return dirs.join("&");
|
|
}
|
|
|
|
// Automatically refresh config when Continue-related IDE (e.g. VS Code) settings are changed
|
|
updateIdeSettings(ideSettings: IdeSettings) {
|
|
this.ideSettingsPromise = Promise.resolve(ideSettings);
|
|
this.reloadConfig();
|
|
}
|
|
|
|
private profilesListeners: ((profiles: ProfileDescription[]) => void)[] = [];
|
|
onDidChangeAvailableProfiles(
|
|
listener: (profiles: ProfileDescription[]) => void,
|
|
) {
|
|
this.profilesListeners.push(listener);
|
|
}
|
|
|
|
private notifyProfileListeners(profiles: ProfileDescription[]) {
|
|
for (const listener of this.profilesListeners) {
|
|
listener(profiles);
|
|
}
|
|
}
|
|
|
|
private notifyConfigListerners(newConfig: ContinueConfig) {
|
|
// Notify listeners that config changed
|
|
for (const listener of this.updateListeners) {
|
|
listener(newConfig);
|
|
}
|
|
}
|
|
|
|
private updateListeners: ((newConfig: ContinueConfig) => void)[] = [];
|
|
onConfigUpdate(listener: (newConfig: ContinueConfig) => void) {
|
|
this.updateListeners.push(listener);
|
|
}
|
|
|
|
async reloadConfig() {
|
|
// TODO: this isn't right, there are two different senses in which you want to "reload"
|
|
const newConfig = await this.currentProfile.reloadConfig();
|
|
this.inactiveProfiles.forEach((profile) => profile.clearConfig());
|
|
this.notifyConfigListerners(newConfig);
|
|
}
|
|
|
|
getSerializedConfig(): Promise<BrowserSerializedContinueConfig> {
|
|
return this.currentProfile.getSerializedConfig(
|
|
this.additionalContextProviders,
|
|
);
|
|
}
|
|
|
|
listProfiles(): ProfileDescription[] {
|
|
return this.profiles.map((p) => p.profileDescription);
|
|
}
|
|
|
|
async loadConfig(): Promise<ContinueConfig> {
|
|
return this.currentProfile.loadConfig(this.additionalContextProviders);
|
|
}
|
|
|
|
async llmFromTitle(title?: string): Promise<ILLM> {
|
|
const config = await this.loadConfig();
|
|
const model =
|
|
config.models.find((m) => m.title === title) || config.models[0];
|
|
if (!model) {
|
|
throw new Error("No model found");
|
|
}
|
|
|
|
return model;
|
|
}
|
|
|
|
registerCustomContextProvider(contextProvider: IContextProvider) {
|
|
this.additionalContextProviders.push(contextProvider);
|
|
this.reloadConfig();
|
|
}
|
|
}
|