* feat: add fixed version of the nodejs * revert accidentally committed files * add: unified version of the Node.js that is used locally and on Github Actions * Set itemType for querySubmenuItem This is necessary before calling props.command the same way we do it for non-query item types. Otherwise we receive an 'Unknow provider...' error message in the 'getContextItems' case in the 'panel.webview.onDidReceiveMessage, callback. * include @vscode node module folder we need the @vscode folder containing ripgrep in the distribution. * Amended path for ripgrep executable We have to preprend the 'out' folder in order to find the ripgrep executable in the distribution. Prepending 'out' during development is not necessary. We need a way to distinguish in 'ideProtocol'? * implemented locals context provider * normal to submenu(select thread) for the locals provider * added code context from the call stack * use parameter for callstack retrieving * added thread filtering and handle a edge case * revert accidentally committed file * temporary fix to use refreshSubmenuItems * added updateSubmenuItems request * refactor: changed the interface of threads * polished format and file reading * added a little doc * typo * revert accidentally committed file * ✨ UI for JetBrains autocomplete * 🎨 decouple autocomplete from VS Code extension * ✨ autocomplete in core protocol * 🚧 jetbrains autocomplete fixes * 🐛 successfully get responses for jetbrains autocomplete * Refactored web crawling code for document indexing. The updated code uses a breadth-first search, filters out specific paths, and ensures that websites are not downloaded twice. * update hasDocs to use new pattern * feat: add gitlab context class * feat: update to work as normal context provider * fix: add context provider * feat: add code that comment is based on * docs: add documentation * feat: enable comment filtering * 🐛 fix autocomplete with azure * ✨ jetbrains multiline completions * 🐛 fix file reading in autocomplete * ✨ option to disable jetbrains autocomplete * 📌 update package-lock files * 🐛 fix localhost ollama bug with jetbrains binary * 🔥 disable apply to file in jetbrains for now * 🚸 fix constant re-rendering of code vision in jetbrains * 🔖 update package.json versiojn * 🐛 don't override user temperature value for tab autocomplete model * Fix chat msg formatting in Output for image models (#971) * 📝 tweak docs for "locals" ctx provider * 🩹 small tweak to link filtering logic * Add more C++ extensions for AST parser (#972) * 🔥 remove ruby example file * add claude3 to free trial * 🐛 fix codelens in tutorial * 🧱 change server url * 🐛 don't send image_url if not image type * 🔧 update config schemas * 📌 update npm version to v20.11.0 * 📈 Locally track tokens generated and show stats (#987) * ✨ log tokens generated locally * 💄 UI for usage stats * 🔥 delete unused test file * 🚚 rename core package for publishing on npm * Remove duplicate itemType property (#986) * 🔒️ add .env to .gitignore for npm package * Add SystemContextProvider to context providers so that users can use … (#988) * Add SystemContextProvider to context providers so that users can use their own system cpu and os for a resource * change to OSContextProvider * update descriptor * 🎨 export transformers.js * 🐛 fix /edit for anthropic * 🚑 fix autocomplete by binding function --------- Co-authored-by: my8bit <mail@my8bit.name> Co-authored-by: Ihor Pavlenko <my8bit@users.noreply.github.com> Co-authored-by: Lars Pagh <lp@airsupport.dk> Co-authored-by: commandblock2 <tony_hu@live.com> Co-authored-by: Jason Jacobs <nerfnerd@gmail.com> Co-authored-by: Ben Force <benforce@gmail.com> Co-authored-by: Peter Zaback <pzaback@gmail.com> Co-authored-by: SR_team <sr_team@sr.team>
148 lines
3.6 KiB
TypeScript
148 lines
3.6 KiB
TypeScript
import { Database, open } from "sqlite";
|
|
import sqlite3 from "sqlite3";
|
|
import { Chunk } from "../..";
|
|
import { getDocsSqlitePath, getLanceDbPath } from "../../util/paths";
|
|
|
|
import { downloadPreIndexedDocs } from "./preIndexed";
|
|
import { default as configs } from "./preIndexedDocs";
|
|
|
|
const DOCS_TABLE_NAME = "docs";
|
|
|
|
interface LanceDbDocsRow {
|
|
title: string;
|
|
baseUrl: string;
|
|
// Chunk
|
|
content: string;
|
|
path: string;
|
|
startLine: number;
|
|
endLine: number;
|
|
vector: number[];
|
|
[key: string]: any;
|
|
}
|
|
|
|
let dbDocs:Database;
|
|
|
|
async function getDBDocs() {
|
|
if (!dbDocs) {
|
|
dbDocs = await open({
|
|
filename: getDocsSqlitePath(),
|
|
driver: sqlite3.Database,
|
|
});
|
|
|
|
dbDocs.exec(`CREATE TABLE IF NOT EXISTS docs (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
title STRING NOT NULL,
|
|
baseUrl STRING NOT NULL UNIQUE
|
|
)`);
|
|
}
|
|
|
|
return dbDocs;
|
|
}
|
|
|
|
export async function retrieveDocs(
|
|
baseUrl: string,
|
|
vector: number[],
|
|
nRetrieve: number,
|
|
embeddingsProviderId: string,
|
|
nested: boolean = false,
|
|
): Promise<Chunk[]> {
|
|
const lancedb = await import("vectordb");
|
|
const db = await getDBDocs();
|
|
const lance = await lancedb.connect(getLanceDbPath());
|
|
|
|
const downloadDocs = async () => {
|
|
const config = configs.find((config) => config.startUrl === baseUrl);
|
|
if (config) {
|
|
await downloadPreIndexedDocs(embeddingsProviderId, config.title);
|
|
return await retrieveDocs(
|
|
baseUrl,
|
|
vector,
|
|
nRetrieve,
|
|
embeddingsProviderId,
|
|
true,
|
|
);
|
|
}
|
|
return undefined;
|
|
};
|
|
|
|
const tableNames = await lance.tableNames();
|
|
if (!tableNames.includes(DOCS_TABLE_NAME)) {
|
|
const downloaded = await downloadDocs();
|
|
if (downloaded) return downloaded;
|
|
}
|
|
|
|
const table = await lance.openTable(DOCS_TABLE_NAME);
|
|
let docs: LanceDbDocsRow[] = await table
|
|
.search(vector)
|
|
.limit(nRetrieve)
|
|
.where(`baseUrl = '${baseUrl}'`)
|
|
.execute();
|
|
|
|
docs = docs.filter((doc) => doc.baseUrl === baseUrl);
|
|
|
|
if ((!docs || docs.length === 0) && !nested) {
|
|
const downloaded = await downloadDocs();
|
|
if (downloaded) return downloaded;
|
|
}
|
|
|
|
return docs.map((doc) => ({
|
|
digest: doc.path,
|
|
filepath: doc.path,
|
|
startLine: doc.startLine,
|
|
endLine: doc.endLine,
|
|
index: 0,
|
|
content: doc.content,
|
|
otherMetadata: {
|
|
title: doc.title,
|
|
},
|
|
}));
|
|
}
|
|
|
|
export async function addDocs(
|
|
title: string,
|
|
baseUrl: URL,
|
|
chunks: Chunk[],
|
|
embeddings: number[][],
|
|
) {
|
|
const data: LanceDbDocsRow[] = chunks.map((chunk, i) => ({
|
|
title: chunk.otherMetadata?.title || title,
|
|
baseUrl: baseUrl.toString(),
|
|
content: chunk.content,
|
|
path: chunk.filepath,
|
|
startLine: chunk.startLine,
|
|
endLine: chunk.endLine,
|
|
vector: embeddings[i],
|
|
}));
|
|
|
|
const lancedb = await import("vectordb");
|
|
const lance = await lancedb.connect(getLanceDbPath());
|
|
const tableNames = await lance.tableNames();
|
|
if (!tableNames.includes(DOCS_TABLE_NAME)) {
|
|
await lance.createTable(DOCS_TABLE_NAME, data);
|
|
} else {
|
|
const table = await lance.openTable(DOCS_TABLE_NAME);
|
|
await table.add(data);
|
|
}
|
|
|
|
// Only after add it to SQLite
|
|
const db = await getDBDocs();
|
|
await db.run(
|
|
`INSERT INTO docs (title, baseUrl) VALUES (?, ?)`,
|
|
title,
|
|
baseUrl.toString(),
|
|
);
|
|
}
|
|
|
|
export async function listDocs(): Promise<
|
|
{ title: string; baseUrl: string }[]
|
|
> {
|
|
const db = await getDBDocs();
|
|
const docs = db.all(`SELECT title, baseUrl FROM docs`);
|
|
return docs;
|
|
}
|
|
|
|
export async function hasDoc(baseUrl: string) {
|
|
const db = await getDBDocs();
|
|
const doc = await db.get(`SELECT title FROM docs WHERE baseUrl =?`, baseUrl);
|
|
return!!doc;
|
|
}
|