@devflow-tools/knowledge-engine 0.1.0
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/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/knowledge-engine.d.ts +14 -0
- package/dist/knowledge-engine.d.ts.map +1 -0
- package/dist/knowledge-engine.js +64 -0
- package/dist/knowledge-engine.js.map +1 -0
- package/package.json +30 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { IKnowledgeEngine, KnowledgeEntry, KnowledgeSource, SearchOptions, SyncResult, KnowledgeSourceStatus, IDataProvider } from "@devflow-tools/sdk";
|
|
2
|
+
export declare class KnowledgeEngine implements IKnowledgeEngine {
|
|
3
|
+
private provider;
|
|
4
|
+
private sourcesKey;
|
|
5
|
+
constructor(provider: IDataProvider);
|
|
6
|
+
private loadSourceRegistry;
|
|
7
|
+
private saveSourceRegistry;
|
|
8
|
+
registerSource(source: KnowledgeSource): Promise<void>;
|
|
9
|
+
syncDocs(_pluginName?: string): Promise<SyncResult[]>;
|
|
10
|
+
search(query: string, options?: SearchOptions): Promise<KnowledgeEntry[]>;
|
|
11
|
+
lookup(symbol: string, _scope?: string): Promise<KnowledgeEntry | null>;
|
|
12
|
+
getSources(): Promise<KnowledgeSourceStatus[]>;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=knowledge-engine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"knowledge-engine.d.ts","sourceRoot":"","sources":["../src/knowledge-engine.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAAE,cAAc,EAAE,eAAe,EACjD,aAAa,EAAE,UAAU,EAAE,qBAAqB,EAAE,aAAa,EAChE,MAAM,oBAAoB,CAAC;AAE5B,qBAAa,eAAgB,YAAW,gBAAgB;IACtD,OAAO,CAAC,QAAQ,CAAgB;IAChC,OAAO,CAAC,UAAU,CAAuB;gBAE7B,QAAQ,EAAE,aAAa;YAIrB,kBAAkB;YAoBlB,kBAAkB;IAW1B,cAAc,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IAMtD,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;IAIrD,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;IAiBzE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC;IASvE,UAAU,IAAI,OAAO,CAAC,qBAAqB,EAAE,CAAC;CAIrD"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export class KnowledgeEngine {
|
|
2
|
+
provider;
|
|
3
|
+
sourcesKey = "knowledge:sources";
|
|
4
|
+
constructor(provider) {
|
|
5
|
+
this.provider = provider;
|
|
6
|
+
}
|
|
7
|
+
async loadSourceRegistry() {
|
|
8
|
+
const sources = new Map();
|
|
9
|
+
const raw = await this.provider.kvGet(this.sourcesKey);
|
|
10
|
+
if (raw) {
|
|
11
|
+
const data = raw;
|
|
12
|
+
for (const item of data) {
|
|
13
|
+
sources.set(item.name, {
|
|
14
|
+
source: item.source,
|
|
15
|
+
status: item.status,
|
|
16
|
+
lastSyncTime: item.lastSyncTime,
|
|
17
|
+
entryCount: item.entryCount,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return sources;
|
|
22
|
+
}
|
|
23
|
+
async saveSourceRegistry(sources) {
|
|
24
|
+
const data = Array.from(sources.entries()).map(([name, status]) => ({
|
|
25
|
+
name,
|
|
26
|
+
source: status.source,
|
|
27
|
+
status: status.status,
|
|
28
|
+
lastSyncTime: status.lastSyncTime,
|
|
29
|
+
entryCount: status.entryCount,
|
|
30
|
+
}));
|
|
31
|
+
await this.provider.kvSet(this.sourcesKey, data);
|
|
32
|
+
}
|
|
33
|
+
async registerSource(source) {
|
|
34
|
+
const sources = await this.loadSourceRegistry();
|
|
35
|
+
sources.set(source.name, { source, status: "idle" });
|
|
36
|
+
await this.saveSourceRegistry(sources);
|
|
37
|
+
}
|
|
38
|
+
async syncDocs(_pluginName) {
|
|
39
|
+
return [];
|
|
40
|
+
}
|
|
41
|
+
async search(query, options) {
|
|
42
|
+
const limit = options?.limit ?? 10;
|
|
43
|
+
const rows = await this.provider.sqlQuery("SELECT id, source, title, content FROM devflow_knowledge_entries WHERE content LIKE ? OR title LIKE ? LIMIT ?", [`%${query}%`, `%${query}%`, limit]);
|
|
44
|
+
return rows.map((r) => ({
|
|
45
|
+
id: r.id,
|
|
46
|
+
source: r.source,
|
|
47
|
+
title: r.title,
|
|
48
|
+
content: r.content,
|
|
49
|
+
embedding: [],
|
|
50
|
+
}));
|
|
51
|
+
}
|
|
52
|
+
async lookup(symbol, _scope) {
|
|
53
|
+
const results = await this.search(symbol, { limit: 5 });
|
|
54
|
+
if (results.length === 0)
|
|
55
|
+
return null;
|
|
56
|
+
const exact = results.find((r) => r.title.toLowerCase().includes(symbol.toLowerCase()));
|
|
57
|
+
return exact ?? null;
|
|
58
|
+
}
|
|
59
|
+
async getSources() {
|
|
60
|
+
const sources = await this.loadSourceRegistry();
|
|
61
|
+
return Array.from(sources.values());
|
|
62
|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C;YAAE,OAAO,IAAI,CAAC;QACtC,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAC/B,CAAC,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,CACrD,CAAC;QACF,OAAO,KAAK,IAAI,IAAI,CAAC;IACvB,CAAC;IAED,KAAK,CAAC,UAAU;QACd,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,kBAAkB,EAAE,CAAC;QAChD,OAAO,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IACtC,CAAC;CACF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@devflow-tools/knowledge-engine",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"import": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "tsc -b",
|
|
15
|
+
"test": "cgnode ../../node_modules/.bin/vitest run",
|
|
16
|
+
"typecheck": "tsc --noEmit",
|
|
17
|
+
"clean": "rm -rf dist"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@devflow-tools/sdk": "*"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"typescript": "^5.5.0",
|
|
24
|
+
"vitest": "^2.0.0"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist"
|
|
28
|
+
],
|
|
29
|
+
"gitHead": "4cede97fc7fc673f929427fac169acab100ca8ed"
|
|
30
|
+
}
|