diff --git a/agent.ts b/agent.ts index 081165a..e4296a2 100644 --- a/agent.ts +++ b/agent.ts @@ -1,16 +1,16 @@ import fs from "node:fs"; -import { - VectorStoreIndex, - storageContextFromDefaults, - Settings, - QueryEngineTool, - ReActAgent, -} from "llamaindex"; import { OllamaEmbedding } from "@llamaindex/ollama"; import { OpenAI } from "@llamaindex/openai"; import { Graph } from "graphology"; +import { + QueryEngineTool, + ReActAgent, + Settings, + storageContextFromDefaults, + VectorStoreIndex, +} from "llamaindex"; -import { STORAGE_DIR, GRAPH_FILE } from "./constants.ts"; +import { GRAPH_FILE, STORAGE_DIR } from "./constants.ts"; // Configure Settings Settings.embedModel = new OllamaEmbedding({ @@ -94,7 +94,7 @@ async function main() { const attr = graph.getNodeAttributes(neighbor); const edges = graph.edges(nodeId, neighbor); const edgeAttr = graph.getEdgeAttributes(edges[0]); - result += `- ${neighbor} (${attr.type}) via ${edgeAttr.type}${attr.title ? ": " + attr.title : ""}\n`; + result += `- ${neighbor} (${attr.type}) via ${edgeAttr.type}${attr.title ? `: ${attr.title}` : ""}\n`; }); return result; } diff --git a/biome.json b/biome.json index 82bcdcf..52d8102 100644 --- a/biome.json +++ b/biome.json @@ -5,5 +5,5 @@ "lineWidth": 80, "lineEnding": "lf" }, - "files": { "includes": ["**", "!!spec-built/**", "!!engine262/**"] } + "files": { "includes": ["**", "!!spec-built", "!!engine262", "!!graphology"] } } diff --git a/bun.lock b/bun.lock index ac3e1f1..13be5a1 100644 --- a/bun.lock +++ b/bun.lock @@ -18,6 +18,7 @@ }, "devDependencies": { "@biomejs/biome": "^2.4.9", + "typescript": "^5.5.2", }, }, }, @@ -172,6 +173,8 @@ "tslib": ["tslib@2.8.1", "", {}, "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w=="], + "typescript": ["typescript@5.9.3", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw=="], + "undici": ["undici@7.24.6", "", {}, "sha512-Xi4agocCbRzt0yYMZGMA6ApD7gvtUFaxm4ZmeacWI4cZxaF6C+8I8QfofC20NAePiB/IcvZmzkJ7XPa471AEtA=="], "undici-types": ["undici-types@7.16.0", "", {}, "sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw=="], diff --git a/package.json b/package.json index e1c9b80..4445e42 100644 --- a/package.json +++ b/package.json @@ -3,8 +3,11 @@ "version": "1.0.0", "main": "index.js", "scripts": { + "type-check": "tsc --noEmit", "lint": "biome check .", - "format": "biome format .", + "lint:fix": "biome check . --write", + "lint:fix:unsafe": "biome check . --write --unsafe", + "format:fix": "biome format . --write", "ingest": "bun run setup/ingest.ts", "agent": "bun run agent.ts", "build": "bun run setup/build_graph.ts", @@ -28,6 +31,7 @@ "llamaindex": "^0.12.1" }, "devDependencies": { + "typescript": "^5.5.2", "@biomejs/biome": "^2.4.9" } -} \ No newline at end of file +} diff --git a/setup/build_graph.ts b/setup/build_graph.ts index 817e0a6..67dd510 100644 --- a/setup/build_graph.ts +++ b/setup/build_graph.ts @@ -1,11 +1,12 @@ -import fs from "fs"; -import path from "path"; -import { glob } from "glob"; +import fs from "node:fs"; +import path from "node:path"; import * as cheerio from "cheerio"; +import { glob } from "glob"; import { Graph } from "graphology"; const SPEC_DIR = "./spec-built/multipage"; const CODE_DIR = "./engine262/src"; + import { GRAPH_FILE } from "../constants.ts"; async function buildGraph() { @@ -24,7 +25,7 @@ async function buildGraph() { const content = fs.readFileSync(file, "utf-8"); const $ = cheerio.load(content); - $("emu-clause").each((i, elem) => { + $("emu-clause").each((_i, elem) => { const id = $(elem).attr("id"); const title = $(elem).find("h1").first().text().trim(); @@ -36,12 +37,12 @@ async function buildGraph() { // Extract internal links $(elem) .find("a[href]") - .each((j, link) => { + .each((_j, link) => { const href = $(link).attr("href"); - if (href && href.includes("#")) { - const [targetFile, targetId] = href.split("#"); + if (href?.includes("#")) { + const [_targetFile, targetId] = href.split("#"); // We only care about links to other sections for now - if (targetId && targetId.startsWith("sec-")) { + if (targetId?.startsWith("sec-")) { // Add relationship later if nodes exist } } @@ -54,14 +55,14 @@ async function buildGraph() { for (const file of htmlFiles) { const content = fs.readFileSync(file, "utf-8"); const $ = cheerio.load(content); - $("emu-clause").each((i, elem) => { + $("emu-clause").each((_i, elem) => { const sourceId = $(elem).attr("id"); if (sourceId && graph.hasNode(sourceId)) { $(elem) .find("a[href]") - .each((j, link) => { + .each((_j, link) => { const href = $(link).attr("href"); - if (href && href.includes("#")) { + if (href?.includes("#")) { const [, targetId] = href.split("#"); if ( targetId && diff --git a/setup/ingest.ts b/setup/ingest.ts index c87dc36..adb2d41 100644 --- a/setup/ingest.ts +++ b/setup/ingest.ts @@ -1,15 +1,15 @@ -import fs from "fs"; -import path from "path"; -import { glob } from "glob"; +import fs from "node:fs"; +import path from "node:path"; +import { OllamaEmbedding } from "@llamaindex/ollama"; import * as cheerio from "cheerio"; +import { glob } from "glob"; import { Document, - VectorStoreIndex, + SentenceSplitter, Settings, storageContextFromDefaults, - SentenceSplitter, + VectorStoreIndex, } from "llamaindex"; -import { OllamaEmbedding } from "@llamaindex/ollama"; // Configure Settings Settings.embedModel = new OllamaEmbedding({ @@ -17,7 +17,8 @@ Settings.embedModel = new OllamaEmbedding({ }); const SPEC_DIR = "./spec-built/multipage"; -const CODE_DIR = "./engine262/src"; +const _CODE_DIR = "./engine262/src"; + import { STORAGE_DIR } from "../constants.ts"; // Initialize a SentenceSplitter with even smaller chunk size @@ -34,7 +35,7 @@ async function ingestSpec() { const content = fs.readFileSync(file, "utf-8"); const $ = cheerio.load(content); - $("emu-clause").each((i, elem) => { + $("emu-clause").each((_i, elem) => { const id = $(elem).attr("id"); const title = $(elem).find("h1").first().text().trim(); // Only extract immediate text to avoid excessive chunking of child sections @@ -104,7 +105,7 @@ async function main() { storageContext, }); console.log("Existing index found, continuing ingestion..."); - } catch (e) { + } catch (_e) { console.log("No existing index found, starting fresh."); }