forked from Ikalus1988/MisakaNet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.ts
More file actions
66 lines (60 loc) 路 1.96 KB
/
Copy pathconfig.ts
File metadata and controls
66 lines (60 loc) 路 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { execFileSync } from "child_process";
import os from "os";
import path from "path";
import type { ContinueConfig } from "@continuedev/config-yaml";
const MISAKANET_REPO = process.env.MISAKANET_REPO ?? path.join(os.homedir(), "MisakaNet");
const MISAKANET_SEARCH = path.join(MISAKANET_REPO, "scripts", "misaka_search_json.py");
type MisakaResult = {
title: string;
score: number;
path: string;
domain?: string;
status?: string;
snippet: string;
};
function formatMisakaResults(query: string, results: MisakaResult[]): string {
if (!results.length) {
return `No MisakaNet results found for "${query}".`;
}
const lines = [`MisakaNet search results for "${query}":`, ""];
results.forEach((result, index) => {
const score = Math.round(result.score * 100);
const tags = [result.domain, result.status].filter(Boolean).join(" 路 ");
lines.push(`${index + 1}. ${result.title}`);
lines.push(` Score: ${score}%${tags ? ` (${tags})` : ""}`);
lines.push(` Path: ${result.path}`);
lines.push(` Snippet: ${result.snippet}`);
lines.push("");
});
return lines.join("\n").trim();
}
const config: ContinueConfig = {
contextProviders: [
{
title: "misaka",
displayTitle: "MisakaNet Search",
description: "Search local MisakaNet lessons and inject title, score, path, and snippet.",
type: "query",
getContextItems: async (query: string) => {
const raw = execFileSync(
"python3",
[MISAKANET_SEARCH, query, "--top", "5"],
{
cwd: MISAKANET_REPO,
encoding: "utf8",
maxBuffer: 1024 * 1024,
},
);
const payload = JSON.parse(raw) as { results: MisakaResult[] };
return [
{
name: `MisakaNet: ${query}`,
description: "Top MisakaNet lesson matches",
content: formatMisakaResults(query, payload.results),
},
];
},
},
],
};
export default config;