dsh-codebase-chat 0.25.0 → 0.25.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +118 -3
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +64 -0
- package/dist/index.js.map +1 -1
- package/lib/index.js +1 -1
- package/package.json +4 -1
package/dist/index.d.ts
CHANGED
|
@@ -300,4 +300,7 @@ declare function buildApplyPrompt(filePath: string, newContent: string, projectN
|
|
|
300
300
|
*/
|
|
301
301
|
declare function buildToolPrompt(tool: string, opts: ToolPromptOptions): string;
|
|
302
302
|
|
|
303
|
-
|
|
303
|
+
declare function isLocalLlmEnabled(): boolean;
|
|
304
|
+
declare function callLocalLlm(prompt: string, lang?: string): Promise<string>;
|
|
305
|
+
|
|
306
|
+
export { CONFIG_FILE, type CloneGroup, type CodeChunk, type CodeIndex, type ConfigLang, type ContextOptions, type ContextResult, type Cycle, type DiffScope, type HealthReport, type Hotspot, type ImpactDependent, type ImpactReport, type ImpactResult, type IndexedFile, type InvertedIndex, type ProjectConfig, type ToolPromptOptions, type UnusedExport, analyzeImpact, analyzeProject, brandSignature, buildApplyPrompt, buildAsciiBanner, buildAuditPrompt, buildBuildPrompt, buildCeoPrompt, buildChatPrompt, buildContext, buildCreaPrompt, buildExplainPrompt, buildGitPrompt, buildIndex, buildIntelligencePrompt, buildPlayerPrompt, buildRefactorPrompt, buildReportPrompt, buildSearchPrompt, buildTasksPrompt, buildToolPrompt, callLocalLlm, chunkByTokens, clearConfigCache, cosineSimilarity, countTokens, disposeTreeSitter, embedIndex, ensureTreeSitterForExt, extractChunks, findProjectRoot, formatHealthReport, formatHealthReportMd, formatImpactReport, formatImpactReportMd, getCacheDir, getChangedFiles, getEmbedding, getEmbeddings, getExtractor, getIndex, globToRegExp, initTreeSitter, isLocalLlmEnabled, langInstruction, loadIndex, loadProjectConfig, matchesAnyGlob, normalizeLabels, resolveProjectPath, saveIndex, scoreChunks, selectChunks, styleInstruction, treeSitterReady, truncateToTokens };
|
package/dist/index.js
CHANGED
|
@@ -2777,6 +2777,68 @@ function buildToolPrompt(tool, opts) {
|
|
|
2777
2777
|
if (!builder) throw new Error(`unknown prompt tool: ${tool}`);
|
|
2778
2778
|
return normalizeLabels(builder(opts), opts.lang || "fr");
|
|
2779
2779
|
}
|
|
2780
|
+
|
|
2781
|
+
// src/local-llm.ts
|
|
2782
|
+
import { existsSync as existsSync2 } from "fs";
|
|
2783
|
+
import { join as join8 } from "path";
|
|
2784
|
+
var DEFAULT_MODEL_URI = "hf:Qwen/Qwen2.5-1.5B-Instruct-GGUF:Q4_K_M";
|
|
2785
|
+
var LOCAL_CONTEXT_SIZE = 8192;
|
|
2786
|
+
var LOCAL_MAX_TOKENS = 1024;
|
|
2787
|
+
function isLocalLlmEnabled() {
|
|
2788
|
+
return !!(process.env.CODEBASE_LOCAL_LLM || "").trim();
|
|
2789
|
+
}
|
|
2790
|
+
function configuredModel() {
|
|
2791
|
+
const v = (process.env.CODEBASE_LOCAL_LLM || "").trim();
|
|
2792
|
+
if (!v || v === "1" || v.toLowerCase() === "true") return DEFAULT_MODEL_URI;
|
|
2793
|
+
return v;
|
|
2794
|
+
}
|
|
2795
|
+
async function importLlama() {
|
|
2796
|
+
try {
|
|
2797
|
+
return await import("node-llama-cpp");
|
|
2798
|
+
} catch {
|
|
2799
|
+
throw new Error("Local LLM needs the optional dependency: npm i node-llama-cpp");
|
|
2800
|
+
}
|
|
2801
|
+
}
|
|
2802
|
+
var modelPromise = null;
|
|
2803
|
+
function loadLocalModel() {
|
|
2804
|
+
if (!modelPromise) {
|
|
2805
|
+
modelPromise = (async () => {
|
|
2806
|
+
const spec = configuredModel();
|
|
2807
|
+
let modelPath = spec;
|
|
2808
|
+
if (spec.startsWith("hf:")) {
|
|
2809
|
+
const { createModelDownloader } = await importLlama();
|
|
2810
|
+
const downloader = await createModelDownloader({
|
|
2811
|
+
modelUri: spec,
|
|
2812
|
+
dirPath: join8(getCacheDir(), "models")
|
|
2813
|
+
});
|
|
2814
|
+
modelPath = await downloader.download();
|
|
2815
|
+
} else if (!existsSync2(spec)) {
|
|
2816
|
+
throw new Error(`Local model not found: ${spec}`);
|
|
2817
|
+
}
|
|
2818
|
+
const { getLlama } = await importLlama();
|
|
2819
|
+
const llama = await getLlama();
|
|
2820
|
+
return llama.loadModel({ modelPath });
|
|
2821
|
+
})();
|
|
2822
|
+
modelPromise.catch(() => {
|
|
2823
|
+
modelPromise = null;
|
|
2824
|
+
});
|
|
2825
|
+
}
|
|
2826
|
+
return modelPromise;
|
|
2827
|
+
}
|
|
2828
|
+
async function callLocalLlm(prompt, lang = "fr") {
|
|
2829
|
+
const model = await loadLocalModel();
|
|
2830
|
+
const { LlamaChatSession } = await importLlama();
|
|
2831
|
+
const context = await model.createContext({ contextSize: LOCAL_CONTEXT_SIZE });
|
|
2832
|
+
try {
|
|
2833
|
+
const session = new LlamaChatSession({
|
|
2834
|
+
contextSequence: context.getSequence(),
|
|
2835
|
+
systemPrompt: lang === "en" ? "You are a senior codebase analyst. Be precise and cite files with [source: path:line]." : "Tu es un analyste codebase senior. Sois precis et cite les fichiers avec [source: chemin:ligne]."
|
|
2836
|
+
});
|
|
2837
|
+
return await session.prompt(prompt, { temperature: 0.2, maxTokens: LOCAL_MAX_TOKENS });
|
|
2838
|
+
} finally {
|
|
2839
|
+
await context.dispose();
|
|
2840
|
+
}
|
|
2841
|
+
}
|
|
2780
2842
|
export {
|
|
2781
2843
|
CONFIG_FILE,
|
|
2782
2844
|
analyzeImpact,
|
|
@@ -2800,6 +2862,7 @@ export {
|
|
|
2800
2862
|
buildSearchPrompt,
|
|
2801
2863
|
buildTasksPrompt,
|
|
2802
2864
|
buildToolPrompt,
|
|
2865
|
+
callLocalLlm,
|
|
2803
2866
|
chunkByTokens,
|
|
2804
2867
|
clearConfigCache,
|
|
2805
2868
|
cosineSimilarity,
|
|
@@ -2821,6 +2884,7 @@ export {
|
|
|
2821
2884
|
getIndex,
|
|
2822
2885
|
globToRegExp,
|
|
2823
2886
|
initTreeSitter,
|
|
2887
|
+
isLocalLlmEnabled,
|
|
2824
2888
|
langInstruction,
|
|
2825
2889
|
loadIndex,
|
|
2826
2890
|
loadProjectConfig,
|