* 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>
626 lines
19 KiB
TypeScript
626 lines
19 KiB
TypeScript
import { v4 as uuidv4 } from "uuid";
|
|
import type {
|
|
ContextItemId,
|
|
IDE,
|
|
IndexingProgressUpdate,
|
|
SiteIndexingConfig,
|
|
} from ".";
|
|
import { CompletionProvider } from "./autocomplete/completionProvider.js";
|
|
import { ConfigHandler } from "./config/ConfigHandler.js";
|
|
import {
|
|
setupApiKeysMode,
|
|
setupFreeTrialMode,
|
|
setupLocalAfterFreeTrial,
|
|
setupLocalMode,
|
|
} from "./config/onboarding.js";
|
|
import { createNewPromptFile } from "./config/promptFile.js";
|
|
import { addModel, addOpenAIKey, deleteModel } from "./config/util.js";
|
|
import { ContinueServerClient } from "./continueServer/stubs/client.js";
|
|
import { ControlPlaneClient } from "./control-plane/client";
|
|
import { CodebaseIndexer, PauseToken } from "./indexing/CodebaseIndexer.js";
|
|
import { DocsService } from "./indexing/docs/DocsService";
|
|
import TransformersJsEmbeddingsProvider from "./indexing/embeddings/TransformersJsEmbeddingsProvider.js";
|
|
import Ollama from "./llm/llms/Ollama.js";
|
|
import type { FromCoreProtocol, ToCoreProtocol } from "./protocol";
|
|
import { GlobalContext } from "./util/GlobalContext.js";
|
|
import { logDevData } from "./util/devdata.js";
|
|
import { DevDataSqliteDb } from "./util/devdataSqlite.js";
|
|
import { fetchwithRequestOptions } from "./util/fetchWithOptions.js";
|
|
import historyManager from "./util/history.js";
|
|
import type { IMessenger, Message } from "./util/messenger";
|
|
import { editConfigJson } from "./util/paths.js";
|
|
import { Telemetry } from "./util/posthog.js";
|
|
import { streamDiffLines } from "./util/verticalEdit.js";
|
|
|
|
export class Core {
|
|
// implements IMessenger<ToCoreProtocol, FromCoreProtocol>
|
|
configHandler: ConfigHandler;
|
|
codebaseIndexerPromise: Promise<CodebaseIndexer>;
|
|
completionProvider: CompletionProvider;
|
|
continueServerClientPromise: Promise<ContinueServerClient>;
|
|
indexingState: IndexingProgressUpdate;
|
|
controlPlaneClient: ControlPlaneClient;
|
|
private globalContext = new GlobalContext();
|
|
private docsService = DocsService.getInstance();
|
|
private readonly indexingPauseToken = new PauseToken(
|
|
this.globalContext.get("indexingPaused") === true,
|
|
);
|
|
|
|
private abortedMessageIds: Set<string> = new Set();
|
|
|
|
private selectedModelTitle: string | undefined;
|
|
|
|
private async config() {
|
|
return this.configHandler.loadConfig();
|
|
}
|
|
|
|
private async getSelectedModel() {
|
|
return await this.configHandler.llmFromTitle(this.selectedModelTitle);
|
|
}
|
|
|
|
invoke<T extends keyof ToCoreProtocol>(
|
|
messageType: T,
|
|
data: ToCoreProtocol[T][0],
|
|
): ToCoreProtocol[T][1] {
|
|
return this.messenger.invoke(messageType, data);
|
|
}
|
|
|
|
// TODO: It shouldn't actually need an IDE type, because this can happen
|
|
// through the messenger (it does in the case of any non-VS Code IDEs already)
|
|
constructor(
|
|
private readonly messenger: IMessenger<ToCoreProtocol, FromCoreProtocol>,
|
|
private readonly ide: IDE,
|
|
private readonly onWrite: (text: string) => Promise<void> = async () => {},
|
|
) {
|
|
this.indexingState = { status: "loading", desc: "loading", progress: 0 };
|
|
const ideSettingsPromise = messenger.request("getIdeSettings", undefined);
|
|
const sessionInfoPromise = messenger.request("getControlPlaneSessionInfo", {
|
|
silent: true,
|
|
});
|
|
this.controlPlaneClient = new ControlPlaneClient(sessionInfoPromise);
|
|
this.configHandler = new ConfigHandler(
|
|
this.ide,
|
|
ideSettingsPromise,
|
|
this.onWrite,
|
|
this.controlPlaneClient,
|
|
);
|
|
this.configHandler.onConfigUpdate(
|
|
(() => this.messenger.send("configUpdate", undefined)).bind(this),
|
|
);
|
|
this.configHandler.onDidChangeAvailableProfiles((profiles) =>
|
|
this.messenger.send("didChangeAvailableProfiles", { profiles }),
|
|
);
|
|
|
|
// Codebase Indexer and ContinueServerClient depend on IdeSettings
|
|
let codebaseIndexerResolve: (_: any) => void | undefined;
|
|
this.codebaseIndexerPromise = new Promise(
|
|
async (resolve) => (codebaseIndexerResolve = resolve),
|
|
);
|
|
|
|
let continueServerClientResolve: (_: any) => void | undefined;
|
|
this.continueServerClientPromise = new Promise(
|
|
(resolve) => (continueServerClientResolve = resolve),
|
|
);
|
|
|
|
ideSettingsPromise.then((ideSettings) => {
|
|
const continueServerClient = new ContinueServerClient(
|
|
ideSettings.remoteConfigServerUrl,
|
|
ideSettings.userToken,
|
|
);
|
|
continueServerClientResolve(continueServerClient);
|
|
|
|
codebaseIndexerResolve(
|
|
new CodebaseIndexer(
|
|
this.configHandler,
|
|
this.ide,
|
|
this.indexingPauseToken,
|
|
continueServerClient,
|
|
),
|
|
);
|
|
this.ide
|
|
.getWorkspaceDirs()
|
|
.then((dirs) => this.refreshCodebaseIndex(dirs));
|
|
});
|
|
|
|
const getLlm = async () => {
|
|
const config = await this.configHandler.loadConfig();
|
|
const selected = this.globalContext.get("selectedTabAutocompleteModel");
|
|
return (
|
|
config.tabAutocompleteModels?.find(
|
|
(model) => model.title === selected,
|
|
) ?? config.tabAutocompleteModels?.[0]
|
|
);
|
|
};
|
|
this.completionProvider = new CompletionProvider(
|
|
this.configHandler,
|
|
ide,
|
|
getLlm,
|
|
(e) => {},
|
|
(..._) => Promise.resolve([]),
|
|
);
|
|
|
|
const on = this.messenger.on.bind(this.messenger);
|
|
|
|
this.messenger.onError((err) => {
|
|
console.error(err);
|
|
this.messenger.request("errorPopup", { message: err.message });
|
|
});
|
|
|
|
// New
|
|
on("update/modelChange", (msg) => {
|
|
this.selectedModelTitle = msg.data;
|
|
});
|
|
|
|
on("update/selectTabAutocompleteModel", async (msg) => {
|
|
this.globalContext.update("selectedTabAutocompleteModel", msg.data);
|
|
this.configHandler.reloadConfig();
|
|
});
|
|
|
|
// Special
|
|
on("abort", (msg) => {
|
|
this.abortedMessageIds.add(msg.messageId);
|
|
});
|
|
|
|
on("ping", (msg) => {
|
|
if (msg.data !== "ping") {
|
|
throw new Error("ping message incorrect");
|
|
}
|
|
return "pong";
|
|
});
|
|
|
|
// History
|
|
on("history/list", (msg) => {
|
|
return historyManager.list(msg.data);
|
|
});
|
|
on("history/delete", (msg) => {
|
|
historyManager.delete(msg.data.id);
|
|
});
|
|
on("history/load", (msg) => {
|
|
return historyManager.load(msg.data.id);
|
|
});
|
|
on("history/save", (msg) => {
|
|
historyManager.save(msg.data);
|
|
});
|
|
|
|
// Dev data
|
|
on("devdata/log", (msg) => {
|
|
logDevData(msg.data.tableName, msg.data.data);
|
|
});
|
|
|
|
// Edit config
|
|
on("config/addModel", (msg) => {
|
|
const model = msg.data.model;
|
|
addModel(model);
|
|
this.configHandler.reloadConfig();
|
|
});
|
|
on("config/addOpenAiKey", (msg) => {
|
|
addOpenAIKey(msg.data);
|
|
this.configHandler.reloadConfig();
|
|
});
|
|
on("config/deleteModel", (msg) => {
|
|
deleteModel(msg.data.title);
|
|
this.configHandler.reloadConfig();
|
|
});
|
|
on("config/newPromptFile", async (msg) => {
|
|
createNewPromptFile(
|
|
this.ide,
|
|
(await this.config()).experimental?.promptPath,
|
|
);
|
|
this.configHandler.reloadConfig();
|
|
});
|
|
on("config/reload", (msg) => {
|
|
this.configHandler.reloadConfig();
|
|
return this.configHandler.getSerializedConfig();
|
|
});
|
|
on("config/ideSettingsUpdate", (msg) => {
|
|
this.configHandler.updateIdeSettings(msg.data);
|
|
});
|
|
on("config/listProfiles", (msg) => {
|
|
return this.configHandler.listProfiles();
|
|
});
|
|
|
|
// Context providers
|
|
on("context/addDocs", async (msg) => {
|
|
const siteIndexingConfig: SiteIndexingConfig = {
|
|
startUrl: msg.data.startUrl,
|
|
rootUrl: msg.data.rootUrl,
|
|
title: msg.data.title,
|
|
maxDepth: msg.data.maxDepth,
|
|
faviconUrl: new URL("/favicon.ico", msg.data.rootUrl).toString(),
|
|
};
|
|
|
|
for await (const _ of this.docsService.indexAndAdd(
|
|
siteIndexingConfig,
|
|
new TransformersJsEmbeddingsProvider(),
|
|
)) {
|
|
}
|
|
this.ide.infoPopup(`Successfully indexed ${msg.data.title}`);
|
|
this.messenger.send("refreshSubmenuItems", undefined);
|
|
});
|
|
on("context/removeDocs", async (msg) => {
|
|
const baseUrl = msg.data.baseUrl;
|
|
await this.docsService.delete(baseUrl);
|
|
this.messenger.send("refreshSubmenuItems", undefined);
|
|
});
|
|
on("context/loadSubmenuItems", async (msg) => {
|
|
const config = await this.config();
|
|
const items = config.contextProviders
|
|
?.find((provider) => provider.description.title === msg.data.title)
|
|
?.loadSubmenuItems({
|
|
ide: this.ide,
|
|
fetch: (url, init) =>
|
|
fetchwithRequestOptions(url, init, config.requestOptions),
|
|
});
|
|
return items || [];
|
|
});
|
|
on("context/getContextItems", async (msg) => {
|
|
const { name, query, fullInput, selectedCode } = msg.data;
|
|
const config = await this.config();
|
|
const llm = await this.getSelectedModel();
|
|
const provider = config.contextProviders?.find(
|
|
(provider) => provider.description.title === name,
|
|
);
|
|
if (!provider) {
|
|
return [];
|
|
}
|
|
|
|
try {
|
|
const id: ContextItemId = {
|
|
providerTitle: provider.description.title,
|
|
itemId: uuidv4(),
|
|
};
|
|
const items = await provider.getContextItems(query, {
|
|
llm,
|
|
embeddingsProvider: config.embeddingsProvider,
|
|
fullInput,
|
|
ide,
|
|
selectedCode,
|
|
reranker: config.reranker,
|
|
fetch: (url, init) =>
|
|
fetchwithRequestOptions(url, init, config.requestOptions),
|
|
});
|
|
|
|
Telemetry.capture(
|
|
"useContextProvider",
|
|
{
|
|
name: provider.description.title,
|
|
},
|
|
true,
|
|
);
|
|
|
|
return items.map((item) => ({
|
|
...item,
|
|
id,
|
|
}));
|
|
} catch (e) {
|
|
this.ide.errorPopup(`Error getting context items from ${name}: ${e}`);
|
|
return [];
|
|
}
|
|
});
|
|
|
|
on("config/getSerializedProfileInfo", async (msg) => {
|
|
return {
|
|
config: await this.configHandler.getSerializedConfig(),
|
|
profileId: this.configHandler.currentProfile.profileId,
|
|
};
|
|
});
|
|
|
|
async function* llmStreamChat(
|
|
configHandler: ConfigHandler,
|
|
abortedMessageIds: Set<string>,
|
|
msg: Message<ToCoreProtocol["llm/streamChat"][0]>,
|
|
) {
|
|
const model = await configHandler.llmFromTitle(msg.data.title);
|
|
const gen = model.streamChat(
|
|
msg.data.messages,
|
|
msg.data.completionOptions,
|
|
);
|
|
let next = await gen.next();
|
|
while (!next.done) {
|
|
if (abortedMessageIds.has(msg.messageId)) {
|
|
abortedMessageIds.delete(msg.messageId);
|
|
next = await gen.return({
|
|
completion: "",
|
|
prompt: "",
|
|
completionOptions: {
|
|
...msg.data.completionOptions,
|
|
model: model.model,
|
|
},
|
|
});
|
|
break;
|
|
}
|
|
yield { content: next.value.content };
|
|
next = await gen.next();
|
|
}
|
|
|
|
return { done: true, content: next.value };
|
|
}
|
|
|
|
on("llm/streamChat", (msg) =>
|
|
llmStreamChat(this.configHandler, this.abortedMessageIds, msg),
|
|
);
|
|
|
|
async function* llmStreamComplete(
|
|
configHandler: ConfigHandler,
|
|
abortedMessageIds: Set<string>,
|
|
|
|
msg: Message<ToCoreProtocol["llm/streamComplete"][0]>,
|
|
) {
|
|
const model = await configHandler.llmFromTitle(msg.data.title);
|
|
const gen = model.streamComplete(
|
|
msg.data.prompt,
|
|
msg.data.completionOptions,
|
|
);
|
|
let next = await gen.next();
|
|
while (!next.done) {
|
|
if (abortedMessageIds.has(msg.messageId)) {
|
|
abortedMessageIds.delete(msg.messageId);
|
|
next = await gen.return({
|
|
completion: "",
|
|
prompt: "",
|
|
completionOptions: {
|
|
...msg.data.completionOptions,
|
|
model: model.model,
|
|
},
|
|
});
|
|
break;
|
|
}
|
|
yield { content: next.value };
|
|
next = await gen.next();
|
|
}
|
|
|
|
return { done: true, content: next.value };
|
|
}
|
|
|
|
on("llm/streamComplete", (msg) =>
|
|
llmStreamComplete(this.configHandler, this.abortedMessageIds, msg),
|
|
);
|
|
|
|
on("llm/complete", async (msg) => {
|
|
const model = await this.configHandler.llmFromTitle(msg.data.title);
|
|
const completion = await model.complete(
|
|
msg.data.prompt,
|
|
msg.data.completionOptions,
|
|
);
|
|
return completion;
|
|
});
|
|
on("llm/listModels", async (msg) => {
|
|
const config = await this.configHandler.loadConfig();
|
|
const model =
|
|
config.models.find((model) => model.title === msg.data.title) ??
|
|
config.models.find((model) => model.title?.startsWith(msg.data.title));
|
|
try {
|
|
if (model) {
|
|
return model.listModels();
|
|
} else {
|
|
if (msg.data.title === "Ollama") {
|
|
const models = await new Ollama({ model: "" }).listModels();
|
|
return models;
|
|
} else {
|
|
return undefined;
|
|
}
|
|
}
|
|
} catch (e) {
|
|
console.warn(`Error listing Ollama models: ${e}`);
|
|
return undefined;
|
|
}
|
|
});
|
|
|
|
async function* runNodeJsSlashCommand(
|
|
configHandler: ConfigHandler,
|
|
abortedMessageIds: Set<string>,
|
|
msg: Message<ToCoreProtocol["command/run"][0]>,
|
|
messenger: IMessenger<ToCoreProtocol, FromCoreProtocol>,
|
|
) {
|
|
const {
|
|
input,
|
|
history,
|
|
modelTitle,
|
|
slashCommandName,
|
|
contextItems,
|
|
params,
|
|
historyIndex,
|
|
selectedCode,
|
|
} = msg.data;
|
|
|
|
const config = await configHandler.loadConfig();
|
|
const llm = await configHandler.llmFromTitle(modelTitle);
|
|
const slashCommand = config.slashCommands?.find(
|
|
(sc) => sc.name === slashCommandName,
|
|
);
|
|
if (!slashCommand) {
|
|
throw new Error(`Unknown slash command ${slashCommandName}`);
|
|
}
|
|
|
|
Telemetry.capture(
|
|
"useSlashCommand",
|
|
{
|
|
name: slashCommandName,
|
|
},
|
|
true,
|
|
);
|
|
|
|
const checkActiveInterval = setInterval(() => {
|
|
if (abortedMessageIds.has(msg.messageId)) {
|
|
abortedMessageIds.delete(msg.messageId);
|
|
clearInterval(checkActiveInterval);
|
|
}
|
|
}, 100);
|
|
|
|
for await (const content of slashCommand.run({
|
|
input,
|
|
history,
|
|
llm,
|
|
contextItems,
|
|
params,
|
|
ide,
|
|
addContextItem: (item) => {
|
|
messenger.request("addContextItem", {
|
|
item,
|
|
historyIndex,
|
|
});
|
|
},
|
|
selectedCode,
|
|
config,
|
|
fetch: (url, init) =>
|
|
fetchwithRequestOptions(url, init, config.requestOptions),
|
|
})) {
|
|
if (abortedMessageIds.has(msg.messageId)) {
|
|
abortedMessageIds.delete(msg.messageId);
|
|
break;
|
|
}
|
|
if (content) {
|
|
yield { content };
|
|
}
|
|
}
|
|
clearInterval(checkActiveInterval);
|
|
yield { done: true, content: "" };
|
|
}
|
|
on("command/run", (msg) =>
|
|
runNodeJsSlashCommand(
|
|
this.configHandler,
|
|
this.abortedMessageIds,
|
|
msg,
|
|
this.messenger,
|
|
),
|
|
);
|
|
|
|
// Autocomplete
|
|
on("autocomplete/complete", async (msg) => {
|
|
const outcome =
|
|
await this.completionProvider.provideInlineCompletionItems(
|
|
msg.data,
|
|
undefined,
|
|
);
|
|
return outcome ? [outcome.completion] : [];
|
|
});
|
|
on("autocomplete/accept", async (msg) => {});
|
|
on("autocomplete/cancel", async (msg) => {
|
|
this.completionProvider.cancel();
|
|
});
|
|
|
|
async function* streamDiffLinesGenerator(
|
|
configHandler: ConfigHandler,
|
|
abortedMessageIds: Set<string>,
|
|
msg: Message<ToCoreProtocol["streamDiffLines"][0]>,
|
|
) {
|
|
const data = msg.data;
|
|
const llm = await configHandler.llmFromTitle(msg.data.modelTitle);
|
|
for await (const diffLine of streamDiffLines(
|
|
data.prefix,
|
|
data.highlighted,
|
|
data.suffix,
|
|
llm,
|
|
data.input,
|
|
data.language,
|
|
)) {
|
|
if (abortedMessageIds.has(msg.messageId)) {
|
|
abortedMessageIds.delete(msg.messageId);
|
|
break;
|
|
}
|
|
console.log(diffLine);
|
|
yield { content: diffLine };
|
|
}
|
|
|
|
return { done: true };
|
|
}
|
|
|
|
on("streamDiffLines", (msg) =>
|
|
streamDiffLinesGenerator(this.configHandler, this.abortedMessageIds, msg),
|
|
);
|
|
|
|
on("completeOnboarding", (msg) => {
|
|
const mode = msg.data.mode;
|
|
|
|
Telemetry.capture("onboardingSelection", {
|
|
mode,
|
|
});
|
|
|
|
if (mode === "custom") {
|
|
return;
|
|
}
|
|
|
|
let editConfigJsonCallback: Parameters<typeof editConfigJson>[0];
|
|
|
|
switch (mode) {
|
|
case "local":
|
|
editConfigJsonCallback = setupLocalMode;
|
|
break;
|
|
|
|
case "freeTrial":
|
|
editConfigJsonCallback = setupFreeTrialMode;
|
|
break;
|
|
|
|
case "localAfterFreeTrial":
|
|
editConfigJsonCallback = setupLocalAfterFreeTrial;
|
|
break;
|
|
|
|
case "apiKeys":
|
|
editConfigJsonCallback = setupApiKeysMode;
|
|
break;
|
|
|
|
default:
|
|
console.error(`Invalid mode: ${mode}`);
|
|
editConfigJsonCallback = (config) => config;
|
|
}
|
|
|
|
editConfigJson(editConfigJsonCallback);
|
|
|
|
this.configHandler.reloadConfig();
|
|
});
|
|
|
|
on("addAutocompleteModel", (msg) => {
|
|
editConfigJson((config) => {
|
|
return {
|
|
...config,
|
|
tabAutocompleteModel: msg.data.model,
|
|
};
|
|
});
|
|
this.configHandler.reloadConfig();
|
|
});
|
|
|
|
on("stats/getTokensPerDay", async (msg) => {
|
|
const rows = await DevDataSqliteDb.getTokensPerDay();
|
|
return rows;
|
|
});
|
|
on("stats/getTokensPerModel", async (msg) => {
|
|
const rows = await DevDataSqliteDb.getTokensPerModel();
|
|
return rows;
|
|
});
|
|
on("index/forceReIndex", async (msg) => {
|
|
const dirs = msg.data ? [msg.data] : await this.ide.getWorkspaceDirs();
|
|
this.refreshCodebaseIndex(dirs);
|
|
});
|
|
on("index/setPaused", (msg) => {
|
|
new GlobalContext().update("indexingPaused", msg.data);
|
|
this.indexingPauseToken.paused = msg.data;
|
|
});
|
|
on("index/indexingProgressBarInitialized", async (msg) => {
|
|
// Triggered when progress bar is initialized.
|
|
// If a non-default state has been stored, update the indexing display to that state
|
|
if (this.indexingState.status !== "loading") {
|
|
this.messenger.request("indexProgress", this.indexingState);
|
|
}
|
|
});
|
|
|
|
on("didChangeSelectedProfile", (msg) => {
|
|
this.configHandler.setSelectedProfile(msg.data.id);
|
|
});
|
|
}
|
|
|
|
private indexingCancellationController: AbortController | undefined;
|
|
|
|
private async refreshCodebaseIndex(dirs: string[]) {
|
|
if (this.indexingCancellationController) {
|
|
this.indexingCancellationController.abort();
|
|
}
|
|
this.indexingCancellationController = new AbortController();
|
|
for await (const update of (await this.codebaseIndexerPromise).refresh(
|
|
dirs,
|
|
this.indexingCancellationController.signal,
|
|
)) {
|
|
this.messenger.request("indexProgress", update);
|
|
this.indexingState = update;
|
|
}
|
|
}
|
|
}
|