@aliyunrds/ctxdb 1.0.1-beta.2 → 1.0.1
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/README.md +79 -11
- package/dist/{chunk-TKMIWM6Q.js → chunk-6FZL67GH.js} +3 -1
- package/dist/{chunk-CYCD234A.js → chunk-EUQ3OFCQ.js} +37 -32
- package/dist/chunk-FD3AMXVU.js +111 -0
- package/dist/chunk-IMYLU5C2.js +514 -0
- package/dist/chunk-RZONPKY4.js +185 -0
- package/dist/{chunk-UULWJJT4.js → chunk-TGVURF54.js} +1 -1
- package/dist/{chunk-6S5RJYBC.js → chunk-UH7AJF6F.js} +25 -19
- package/dist/cli/main.js +484 -165
- package/dist/hooks/hermes-post-llm-call.js +220 -0
- package/dist/hooks/hermes-pre-llm-call.js +145 -0
- package/dist/hooks/session-start.js +9 -178
- package/dist/hooks/stop.js +4 -488
- package/dist/hooks/user-prompt-submit.js +8 -105
- package/dist/opencode/index.js +142 -11
- package/dist/setup/skills/contextdb-knowledge/SKILL.md +24 -7
- package/dist/setup/skills/contextdb-memory/SKILL.md +6 -6
- package/package.json +5 -3
|
@@ -5,6 +5,14 @@ import { readFileSync, existsSync, statSync } from "fs";
|
|
|
5
5
|
import { basename, extname } from "path";
|
|
6
6
|
import { homedir } from "os";
|
|
7
7
|
import { resolve } from "path";
|
|
8
|
+
import {
|
|
9
|
+
buildNormalizedGraphContext,
|
|
10
|
+
extractKnowledgeBaseIds,
|
|
11
|
+
extractKnowledgeChunkContent,
|
|
12
|
+
extractKnowledgeChunkSourceLabel,
|
|
13
|
+
extractKnowledgeChunkTags,
|
|
14
|
+
partitionKnowledgeChunks
|
|
15
|
+
} from "@aliyunrds/ctxdb-shared";
|
|
8
16
|
var KB_COLLECTION = "/v1/knowledge/knowledge_bases";
|
|
9
17
|
var DOCUMENTS = "/v1/knowledge/documents";
|
|
10
18
|
var FILES = "/v1/knowledge/files";
|
|
@@ -135,13 +143,12 @@ function expandHome(p) {
|
|
|
135
143
|
}
|
|
136
144
|
function compactChunk(raw) {
|
|
137
145
|
const c = raw ?? {};
|
|
138
|
-
const content =
|
|
139
|
-
const doc_name =
|
|
140
|
-
const
|
|
141
|
-
const kb_id = Array.isArray(kbRaw) ? typeof kbRaw[0] === "string" ? kbRaw[0] : "" : typeof kbRaw === "string" ? kbRaw : "";
|
|
146
|
+
const content = extractKnowledgeChunkContent(raw);
|
|
147
|
+
const doc_name = extractKnowledgeChunkSourceLabel(raw);
|
|
148
|
+
const kb_id = extractKnowledgeBaseIds(raw)[0] ?? "";
|
|
142
149
|
const docIdRaw = c.doc_id;
|
|
143
150
|
const scoreRaw = c.similarity ?? c.rerank_score;
|
|
144
|
-
const
|
|
151
|
+
const tags = extractKnowledgeChunkTags(raw);
|
|
145
152
|
const out = {
|
|
146
153
|
content,
|
|
147
154
|
doc_name,
|
|
@@ -151,34 +158,35 @@ function compactChunk(raw) {
|
|
|
151
158
|
if (typeof docIdRaw === "string" && docIdRaw.length > 0) {
|
|
152
159
|
out.doc_id = docIdRaw;
|
|
153
160
|
}
|
|
154
|
-
if (
|
|
155
|
-
out.tags =
|
|
161
|
+
if (tags.length > 0) {
|
|
162
|
+
out.tags = tags;
|
|
156
163
|
}
|
|
157
164
|
return out;
|
|
158
165
|
}
|
|
159
|
-
function
|
|
166
|
+
function projectKbQueryResponse(raw, projectChunk, options = {}) {
|
|
160
167
|
if (!raw || typeof raw !== "object") return { chunks: [] };
|
|
161
168
|
const r = raw;
|
|
162
169
|
const chunksIn = Array.isArray(r.chunks) ? r.chunks : [];
|
|
170
|
+
const { graphChunks, documentChunks } = partitionKnowledgeChunks(chunksIn);
|
|
171
|
+
const graphContext = buildNormalizedGraphContext(graphChunks, {
|
|
172
|
+
verbose: options.verboseGraph
|
|
173
|
+
});
|
|
163
174
|
const out = {
|
|
164
|
-
chunks:
|
|
175
|
+
chunks: documentChunks.map(projectChunk)
|
|
165
176
|
};
|
|
166
177
|
if (typeof r.total === "number") out.total = r.total;
|
|
178
|
+
if (graphContext) out.graph_context = graphContext;
|
|
167
179
|
return out;
|
|
168
180
|
}
|
|
181
|
+
function compactKbQueryResponse(raw) {
|
|
182
|
+
return projectKbQueryResponse(raw, compactChunk, { verboseGraph: true });
|
|
183
|
+
}
|
|
169
184
|
function minimalChunk(raw) {
|
|
170
185
|
const c = compactChunk(raw);
|
|
171
186
|
return { content: c.content, score: c.score };
|
|
172
187
|
}
|
|
173
188
|
function minimalKbQueryResponse(raw) {
|
|
174
|
-
|
|
175
|
-
const r = raw;
|
|
176
|
-
const chunksIn = Array.isArray(r.chunks) ? r.chunks : [];
|
|
177
|
-
const out = {
|
|
178
|
-
chunks: chunksIn.map(minimalChunk)
|
|
179
|
-
};
|
|
180
|
-
if (typeof r.total === "number") out.total = r.total;
|
|
181
|
-
return out;
|
|
189
|
+
return projectKbQueryResponse(raw, minimalChunk);
|
|
182
190
|
}
|
|
183
191
|
|
|
184
192
|
export {
|
|
@@ -191,8 +199,6 @@ export {
|
|
|
191
199
|
getDocument,
|
|
192
200
|
listDocuments,
|
|
193
201
|
pollIngest,
|
|
194
|
-
compactChunk,
|
|
195
202
|
compactKbQueryResponse,
|
|
196
|
-
minimalChunk,
|
|
197
203
|
minimalKbQueryResponse
|
|
198
204
|
};
|