veryfront 0.1.932 → 0.1.934
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/esm/deno.d.ts +3 -0
- package/esm/deno.js +4 -1
- package/esm/src/discovery/import-rewriter.d.ts +1 -1
- package/esm/src/discovery/import-rewriter.d.ts.map +1 -1
- package/esm/src/discovery/import-rewriter.js +1 -0
- package/esm/src/discovery/transpiler.d.ts.map +1 -1
- package/esm/src/discovery/transpiler.js +2 -0
- package/esm/src/embedding/veryfront-cloud/rag-store.d.ts.map +1 -1
- package/esm/src/embedding/veryfront-cloud/rag-store.js +78 -11
- package/esm/src/knowledge/index.d.ts +75 -0
- package/esm/src/knowledge/index.d.ts.map +1 -0
- package/esm/src/knowledge/index.js +77 -0
- package/esm/src/utils/version-constant.d.ts +1 -1
- package/esm/src/utils/version-constant.js +1 -1
- package/package.json +5 -1
package/esm/deno.d.ts
CHANGED
|
@@ -53,6 +53,7 @@ declare namespace _default {
|
|
|
53
53
|
"./integrations": string;
|
|
54
54
|
"./sandbox": string;
|
|
55
55
|
"./embedding": string;
|
|
56
|
+
"./knowledge": string;
|
|
56
57
|
"./extensions": string;
|
|
57
58
|
"./extensions/llm": string;
|
|
58
59
|
"./extensions/auth": string;
|
|
@@ -94,6 +95,7 @@ declare namespace _default {
|
|
|
94
95
|
"veryfront/components/chat": string;
|
|
95
96
|
"veryfront/sandbox": string;
|
|
96
97
|
"veryfront/embedding": string;
|
|
98
|
+
"veryfront/knowledge": string;
|
|
97
99
|
"veryfront/runs": string;
|
|
98
100
|
"veryfront/eval": string;
|
|
99
101
|
"veryfront/metrics": string;
|
|
@@ -179,6 +181,7 @@ declare namespace _default {
|
|
|
179
181
|
"#veryfront/discovery": string;
|
|
180
182
|
"#veryfront/data": string;
|
|
181
183
|
"#veryfront/errors": string;
|
|
184
|
+
"#veryfront/knowledge": string;
|
|
182
185
|
"#veryfront/eval": string;
|
|
183
186
|
"#veryfront/eval/agent-service": string;
|
|
184
187
|
"#veryfront/metrics": string;
|
package/esm/deno.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export default {
|
|
2
2
|
"name": "veryfront",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.934",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"nodeModulesDir": "auto",
|
|
6
6
|
"minimumDependencyAge": {
|
|
@@ -109,6 +109,7 @@ export default {
|
|
|
109
109
|
"./integrations": "./src/integrations/index.ts",
|
|
110
110
|
"./sandbox": "./src/sandbox/index.ts",
|
|
111
111
|
"./embedding": "./src/embedding/index.ts",
|
|
112
|
+
"./knowledge": "./src/knowledge/index.ts",
|
|
112
113
|
"./extensions": "./src/extensions/index.ts",
|
|
113
114
|
"./extensions/llm": "./src/extensions/llm/index.ts",
|
|
114
115
|
"./extensions/auth": "./src/extensions/auth/index.ts",
|
|
@@ -150,6 +151,7 @@ export default {
|
|
|
150
151
|
"veryfront/components/chat": "./src/react/components/chat/index.ts",
|
|
151
152
|
"veryfront/sandbox": "./src/sandbox/index.ts",
|
|
152
153
|
"veryfront/embedding": "./src/embedding/index.ts",
|
|
154
|
+
"veryfront/knowledge": "./src/knowledge/index.ts",
|
|
153
155
|
"veryfront/runs": "./src/runs/index.ts",
|
|
154
156
|
"veryfront/eval": "./src/eval/index.ts",
|
|
155
157
|
"veryfront/metrics": "./src/metrics/index.ts",
|
|
@@ -235,6 +237,7 @@ export default {
|
|
|
235
237
|
"#veryfront/discovery": "./src/discovery/index.ts",
|
|
236
238
|
"#veryfront/data": "./src/data/index.ts",
|
|
237
239
|
"#veryfront/errors": "./src/errors/index.ts",
|
|
240
|
+
"#veryfront/knowledge": "./src/knowledge/index.ts",
|
|
238
241
|
"#veryfront/eval": "./src/eval/index.ts",
|
|
239
242
|
"#veryfront/eval/agent-service": "./src/eval/agent-service.ts",
|
|
240
243
|
"#veryfront/metrics": "./src/metrics/index.ts",
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* (Deno, Node.js) and handles veryfront package resolution.
|
|
6
6
|
*/
|
|
7
7
|
import { createFileSystem } from "../platform/compat/fs.js";
|
|
8
|
-
export declare const DISCOVERY_GLOBAL_VERYFRONT_MODULES: readonly ["veryfront/agent", "veryfront/tool", "veryfront/platform", "veryfront/prompt", "veryfront/resource", "veryfront/embedding", "veryfront/workflow", "veryfront/work", "veryfront/eval", "veryfront/metrics", "veryfront/schemas"];
|
|
8
|
+
export declare const DISCOVERY_GLOBAL_VERYFRONT_MODULES: readonly ["veryfront/agent", "veryfront/tool", "veryfront/platform", "veryfront/prompt", "veryfront/resource", "veryfront/embedding", "veryfront/knowledge", "veryfront/workflow", "veryfront/work", "veryfront/eval", "veryfront/metrics", "veryfront/schemas"];
|
|
9
9
|
interface DenoRewriteOptions {
|
|
10
10
|
compiled?: boolean;
|
|
11
11
|
resolveSpecifier?: (specifier: string) => string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"import-rewriter.d.ts","sourceRoot":"","sources":["../../../src/src/discovery/import-rewriter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAI5D,eAAO,MAAM,kCAAkC,
|
|
1
|
+
{"version":3,"file":"import-rewriter.d.ts","sourceRoot":"","sources":["../../../src/src/discovery/import-rewriter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAI5D,eAAO,MAAM,kCAAkC,kQAarC,CAAC;AAEX,UAAU,kBAAkB;IAC1B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,gBAAgB,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,MAAM,CAAC;CAClD;AAkHD;;;;;GAKG;AACH,wBAAgB,cAAc,CAC5B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,kBAAuB,GAC/B,MAAM,CA2BR;AAqFD;;;;;GAKG;AACH,wBAAsB,uBAAuB,CAC3C,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,EAClB,EAAE,EAAE,UAAU,CAAC,OAAO,gBAAgB,CAAC,EACvC,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,MAAM,CAAC,CA2PjB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transpiler.d.ts","sourceRoot":"","sources":["../../../src/src/discovery/transpiler.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"transpiler.d.ts","sourceRoot":"","sources":["../../../src/src/discovery/transpiler.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AA2IvD;;GAEG;AACH,wBAAsB,YAAY,CAChC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,OAAO,CAAC,CAkGlB;AAED;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,IAAI,CAE1C"}
|
|
@@ -19,6 +19,7 @@ import * as platformMod from "../platform/index.js";
|
|
|
19
19
|
import * as promptMod from "../prompt/index.js";
|
|
20
20
|
import * as resourceMod from "../resource/index.js";
|
|
21
21
|
import * as embeddingMod from "../embedding/index.js";
|
|
22
|
+
import * as knowledgeMod from "../knowledge/index.js";
|
|
22
23
|
import * as workflowMod from "../workflow/index.js";
|
|
23
24
|
import * as workMod from "../work/index.js";
|
|
24
25
|
import * as evalMod from "../eval/index.js";
|
|
@@ -40,6 +41,7 @@ async function ensureVeryfrontGlobals() {
|
|
|
40
41
|
"veryfront/prompt": promptMod,
|
|
41
42
|
"veryfront/resource": resourceMod,
|
|
42
43
|
"veryfront/embedding": embeddingMod,
|
|
44
|
+
"veryfront/knowledge": knowledgeMod,
|
|
43
45
|
"veryfront/workflow": workflowMod,
|
|
44
46
|
"veryfront/work": workMod,
|
|
45
47
|
"veryfront/eval": evalMod,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rag-store.d.ts","sourceRoot":"","sources":["../../../../src/src/embedding/veryfront-cloud/rag-store.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAIV,QAAQ,EACR,cAAc,EACf,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"rag-store.d.ts","sourceRoot":"","sources":["../../../../src/src/embedding/veryfront-cloud/rag-store.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAIV,QAAQ,EACR,cAAc,EACf,MAAM,aAAa,CAAC;AA4ErB,KAAK,2BAA2B,GAAG,cAAc,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AA6gBtE,wBAAgB,4BAA4B,CAAC,MAAM,EAAE,2BAA2B,GAAG,QAAQ,CA6H1F"}
|
|
@@ -102,6 +102,7 @@ async function requestJson(context, path, init, options) {
|
|
|
102
102
|
}
|
|
103
103
|
function getCloudStoreContext(config) {
|
|
104
104
|
const bootstrap = requireVeryfrontCloudBootstrap();
|
|
105
|
+
const requestContext = getCurrentRequestContext();
|
|
105
106
|
if (!bootstrap.projectSlug) {
|
|
106
107
|
throw INVALID_ARGUMENT.create({
|
|
107
108
|
detail: "VERYFRONT_PROJECT_SLUG not set. Set the environment variable or runtime projectSlug before using the veryfront-cloud RAG store.",
|
|
@@ -111,7 +112,10 @@ function getCloudStoreContext(config) {
|
|
|
111
112
|
apiBaseUrl: bootstrap.apiBaseUrl,
|
|
112
113
|
fetch: createVeryfrontCloudFetch(bootstrap.apiToken),
|
|
113
114
|
projectSlug: bootstrap.projectSlug,
|
|
114
|
-
branch: config.branch ??
|
|
115
|
+
branch: config.branch ?? requestContext?.branch ?? "main",
|
|
116
|
+
environmentName: requestContext?.environmentName ?? null,
|
|
117
|
+
hasRequestContext: requestContext !== null,
|
|
118
|
+
releaseId: requestContext?.releaseId ?? null,
|
|
115
119
|
};
|
|
116
120
|
}
|
|
117
121
|
function getFileChunksPath(context, filePath) {
|
|
@@ -258,7 +262,7 @@ async function listContentFiles(contentDir, contentExtensions) {
|
|
|
258
262
|
files.push(...(await listContentFiles(fullPath, contentExtensions)));
|
|
259
263
|
}
|
|
260
264
|
else if (entry.isFile && contentExtensions.has(extname(entry.name))) {
|
|
261
|
-
files.push(fullPath);
|
|
265
|
+
files.push({ path: fullPath });
|
|
262
266
|
}
|
|
263
267
|
}
|
|
264
268
|
}
|
|
@@ -267,6 +271,67 @@ async function listContentFiles(contentDir, contentExtensions) {
|
|
|
267
271
|
}
|
|
268
272
|
return files;
|
|
269
273
|
}
|
|
274
|
+
function buildContentDirPattern(contentDir) {
|
|
275
|
+
return `${contentDir.replace(/\/+$/, "")}/**`;
|
|
276
|
+
}
|
|
277
|
+
function buildContentFilesQuery(context, contentDir, cursor) {
|
|
278
|
+
const params = new URLSearchParams({
|
|
279
|
+
include_server_functions: "true",
|
|
280
|
+
limit: "100",
|
|
281
|
+
pattern: buildContentDirPattern(contentDir),
|
|
282
|
+
});
|
|
283
|
+
if (!context.releaseId && !context.environmentName) {
|
|
284
|
+
params.set("branch", context.branch);
|
|
285
|
+
}
|
|
286
|
+
if (cursor) {
|
|
287
|
+
params.set("cursor", cursor);
|
|
288
|
+
}
|
|
289
|
+
return params.toString();
|
|
290
|
+
}
|
|
291
|
+
function getPublishedFileListPath(context, contentDir, cursor) {
|
|
292
|
+
const query = buildContentFilesQuery(context, contentDir, cursor);
|
|
293
|
+
const projectRef = encodeURIComponent(context.projectSlug);
|
|
294
|
+
if (context.releaseId) {
|
|
295
|
+
return `/projects/${projectRef}/releases/${encodeURIComponent(context.releaseId)}/files?${query}`;
|
|
296
|
+
}
|
|
297
|
+
if (context.environmentName) {
|
|
298
|
+
return `/projects/${projectRef}/environments/${encodeURIComponent(context.environmentName)}/files?${query}`;
|
|
299
|
+
}
|
|
300
|
+
return `/projects/${projectRef}/files?${query}`;
|
|
301
|
+
}
|
|
302
|
+
function getPublishedFileDetailPath(context, path) {
|
|
303
|
+
const query = new URLSearchParams({ include_server_functions: "true" });
|
|
304
|
+
const projectRef = encodeURIComponent(context.projectSlug);
|
|
305
|
+
const encodedPath = encodeURIComponent(path);
|
|
306
|
+
if (context.releaseId) {
|
|
307
|
+
return `/projects/${projectRef}/releases/${encodeURIComponent(context.releaseId)}/files/${encodedPath}?${query}`;
|
|
308
|
+
}
|
|
309
|
+
if (context.environmentName) {
|
|
310
|
+
return `/projects/${projectRef}/environments/${encodeURIComponent(context.environmentName)}/files/${encodedPath}?${query}`;
|
|
311
|
+
}
|
|
312
|
+
query.set("branch", context.branch);
|
|
313
|
+
return `/projects/${projectRef}/files/${encodedPath}?${query}`;
|
|
314
|
+
}
|
|
315
|
+
async function listPublishedContentFiles(context, contentDir, contentExtensions) {
|
|
316
|
+
const files = [];
|
|
317
|
+
let cursor;
|
|
318
|
+
do {
|
|
319
|
+
const response = await requestJson(context, getPublishedFileListPath(context, contentDir, cursor));
|
|
320
|
+
files.push(...(response?.data ?? [])
|
|
321
|
+
.filter((file) => contentExtensions.has(extname(file.path)))
|
|
322
|
+
.map((file) => ({ path: file.path, content: file.content })));
|
|
323
|
+
cursor = response?.page_info?.next ?? null;
|
|
324
|
+
} while (cursor);
|
|
325
|
+
return files;
|
|
326
|
+
}
|
|
327
|
+
async function readContentFile(context, file) {
|
|
328
|
+
if (file.content !== undefined)
|
|
329
|
+
return file.content;
|
|
330
|
+
if (!context.hasRequestContext)
|
|
331
|
+
return readTextFile(file.path);
|
|
332
|
+
const response = await requestJson(context, getPublishedFileDetailPath(context, file.path));
|
|
333
|
+
return response?.content ?? "";
|
|
334
|
+
}
|
|
270
335
|
export function createVeryfrontCloudRagStore(config) {
|
|
271
336
|
const contentDir = config.contentDir;
|
|
272
337
|
const contentExtensions = new Set(config.contentExtensions ?? [".md", ".mdx", ".txt"]);
|
|
@@ -341,22 +406,24 @@ export function createVeryfrontCloudRagStore(config) {
|
|
|
341
406
|
const context = getCloudStoreContext(config);
|
|
342
407
|
const existingDocuments = await listRagDocuments(context);
|
|
343
408
|
const indexedSources = new Set(existingDocuments.map((doc) => doc.source));
|
|
344
|
-
const files =
|
|
345
|
-
|
|
409
|
+
const files = context.hasRequestContext
|
|
410
|
+
? await listPublishedContentFiles(context, contentDir, contentExtensions)
|
|
411
|
+
: await listContentFiles(contentDir, contentExtensions);
|
|
412
|
+
const newFiles = files.filter((file) => !indexedSources.has(file.path));
|
|
346
413
|
for (const file of newFiles) {
|
|
347
|
-
const content = await
|
|
414
|
+
const content = await readContentFile(context, file);
|
|
348
415
|
if (!content?.trim())
|
|
349
416
|
continue;
|
|
350
417
|
if (content.length > MAX_TEXT_LENGTH) {
|
|
351
|
-
serverLogger.warn(`[rag-store/cloud] Skipping ${file}: exceeds ${MAX_TEXT_LENGTH / 1024 / 1024} MB text limit`);
|
|
418
|
+
serverLogger.warn(`[rag-store/cloud] Skipping ${file.path}: exceeds ${MAX_TEXT_LENGTH / 1024 / 1024} MB text limit`);
|
|
352
419
|
continue;
|
|
353
420
|
}
|
|
354
|
-
const title = file.startsWith(contentDir + "/")
|
|
355
|
-
? file.slice(contentDir.length + 1).replace(/\.[^.]+$/, "")
|
|
356
|
-
: file.replace(/\.[^.]+$/, "");
|
|
357
|
-
const type = extname(file).slice(1);
|
|
421
|
+
const title = file.path.startsWith(contentDir + "/")
|
|
422
|
+
? file.path.slice(contentDir.length + 1).replace(/\.[^.]+$/, "")
|
|
423
|
+
: file.path.replace(/\.[^.]+$/, "");
|
|
424
|
+
const type = extname(file.path).slice(1);
|
|
358
425
|
await ingestDocument(context, config, title, content, {
|
|
359
|
-
source: file,
|
|
426
|
+
source: file.path,
|
|
360
427
|
type,
|
|
361
428
|
});
|
|
362
429
|
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Project knowledge retrieval helpers.
|
|
3
|
+
*
|
|
4
|
+
* @module knowledge
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* import { projectKnowledge } from "veryfront/knowledge";
|
|
9
|
+
*
|
|
10
|
+
* const knowledge = projectKnowledge();
|
|
11
|
+
* await knowledge.index();
|
|
12
|
+
* const result = await knowledge.retrieve("SSO login failure");
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
import "../../_dnt.polyfills.js";
|
|
16
|
+
import type { RagSearchOptions, RagSearchResult, RagStoreBackend } from "../embedding/index.js";
|
|
17
|
+
/** Configuration for project knowledge indexing and retrieval. */
|
|
18
|
+
export interface ProjectKnowledgeConfig {
|
|
19
|
+
/**
|
|
20
|
+
* Project root used to resolve relative local paths.
|
|
21
|
+
*
|
|
22
|
+
* Hosted Veryfront Cloud request contexts ignore this for release-backed
|
|
23
|
+
* content lookup, but local development uses it to find `knowledge/` and
|
|
24
|
+
* `data/knowledge-index.json`.
|
|
25
|
+
*/
|
|
26
|
+
projectDir?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Directory containing source-controlled knowledge files.
|
|
29
|
+
*
|
|
30
|
+
* Defaults to `knowledge`.
|
|
31
|
+
*/
|
|
32
|
+
contentDir?: string;
|
|
33
|
+
/**
|
|
34
|
+
* Local JSON index path.
|
|
35
|
+
*
|
|
36
|
+
* Defaults to `data/knowledge-index.json`.
|
|
37
|
+
*/
|
|
38
|
+
storagePath?: string;
|
|
39
|
+
contentExtensions?: string[];
|
|
40
|
+
model?: string;
|
|
41
|
+
backend?: RagStoreBackend;
|
|
42
|
+
branch?: string;
|
|
43
|
+
topK?: number;
|
|
44
|
+
threshold?: number;
|
|
45
|
+
maxQueryChars?: number;
|
|
46
|
+
}
|
|
47
|
+
/** Per-call options for project knowledge retrieval. */
|
|
48
|
+
export interface ProjectKnowledgeRetrieveOptions extends RagSearchOptions {
|
|
49
|
+
maxQueryChars?: number;
|
|
50
|
+
}
|
|
51
|
+
/** Result returned from project knowledge retrieval. */
|
|
52
|
+
export interface ProjectKnowledgeResult {
|
|
53
|
+
query: string;
|
|
54
|
+
matches: RagSearchResult[];
|
|
55
|
+
context: string;
|
|
56
|
+
}
|
|
57
|
+
/** Helper for indexing and retrieving project knowledge. */
|
|
58
|
+
export interface ProjectKnowledge {
|
|
59
|
+
/**
|
|
60
|
+
* Index configured project knowledge explicitly.
|
|
61
|
+
*
|
|
62
|
+
* Keep this out of the chat request path. Use it during setup, deploy,
|
|
63
|
+
* ingestion, or another controlled lifecycle step.
|
|
64
|
+
*/
|
|
65
|
+
index(): Promise<void>;
|
|
66
|
+
retrieve(query: string, options?: ProjectKnowledgeRetrieveOptions): Promise<ProjectKnowledgeResult>;
|
|
67
|
+
search(query: string, options?: RagSearchOptions): Promise<RagSearchResult[]>;
|
|
68
|
+
}
|
|
69
|
+
/** Normalize a knowledge query before retrieval. */
|
|
70
|
+
export declare function normalizeKnowledgeQuery(query: string, maxChars?: number): string;
|
|
71
|
+
/** Format search results into a deterministic prompt context block. */
|
|
72
|
+
export declare function formatKnowledgeContext(results: RagSearchResult[]): string;
|
|
73
|
+
/** Create a project knowledge helper backed by the configured RAG store. */
|
|
74
|
+
export declare function projectKnowledge(config?: ProjectKnowledgeConfig): ProjectKnowledge;
|
|
75
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/src/knowledge/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,yBAAyB,CAAC;AAIjC,OAAO,KAAK,EACV,gBAAgB,EAChB,eAAe,EAEf,eAAe,EAChB,MAAM,uBAAuB,CAAC;AAQ/B,kEAAkE;AAClE,MAAM,WAAW,sBAAsB;IACrC;;;;;;OAMG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC7B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,eAAe,CAAC;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,wDAAwD;AACxD,MAAM,WAAW,+BAAgC,SAAQ,gBAAgB;IACvE,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,wDAAwD;AACxD,MAAM,WAAW,sBAAsB;IACrC,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,eAAe,EAAE,CAAC;IAC3B,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,4DAA4D;AAC5D,MAAM,WAAW,gBAAgB;IAC/B;;;;;OAKG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB,QAAQ,CACN,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE,+BAA+B,GACxC,OAAO,CAAC,sBAAsB,CAAC,CAAC;IACnC,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC,CAAC;CAC/E;AAOD,oDAAoD;AACpD,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,MAAM,EACb,QAAQ,GAAE,MAAgC,GACzC,MAAM,CAER;AAED,uEAAuE;AACvE,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,eAAe,EAAE,GAAG,MAAM,CAIzE;AAED,4EAA4E;AAC5E,wBAAgB,gBAAgB,CAAC,MAAM,GAAE,sBAA2B,GAAG,gBAAgB,CAmDtF"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Project knowledge retrieval helpers.
|
|
3
|
+
*
|
|
4
|
+
* @module knowledge
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* import { projectKnowledge } from "veryfront/knowledge";
|
|
9
|
+
*
|
|
10
|
+
* const knowledge = projectKnowledge();
|
|
11
|
+
* await knowledge.index();
|
|
12
|
+
* const result = await knowledge.retrieve("SSO login failure");
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
import "../../_dnt.polyfills.js";
|
|
16
|
+
import { ragStore } from "../embedding/index.js";
|
|
17
|
+
import { isAbsolute, join } from "../platform/compat/path/index.js";
|
|
18
|
+
const DEFAULT_CONTENT_DIR = "knowledge";
|
|
19
|
+
const DEFAULT_STORAGE_PATH = "data/knowledge-index.json";
|
|
20
|
+
const DEFAULT_TOP_K = 3;
|
|
21
|
+
const DEFAULT_QUERY_MAX_CHARS = 500;
|
|
22
|
+
function resolveProjectPath(projectDir, path) {
|
|
23
|
+
if (!projectDir || isAbsolute(path))
|
|
24
|
+
return path;
|
|
25
|
+
return join(projectDir, path);
|
|
26
|
+
}
|
|
27
|
+
/** Normalize a knowledge query before retrieval. */
|
|
28
|
+
export function normalizeKnowledgeQuery(query, maxChars = DEFAULT_QUERY_MAX_CHARS) {
|
|
29
|
+
return query.replace(/\s+/g, " ").trim().slice(0, maxChars);
|
|
30
|
+
}
|
|
31
|
+
/** Format search results into a deterministic prompt context block. */
|
|
32
|
+
export function formatKnowledgeContext(results) {
|
|
33
|
+
return results
|
|
34
|
+
.map((result) => `[${result.title}] (score: ${result.score.toFixed(2)})\n${result.text}`)
|
|
35
|
+
.join("\n\n---\n\n");
|
|
36
|
+
}
|
|
37
|
+
/** Create a project knowledge helper backed by the configured RAG store. */
|
|
38
|
+
export function projectKnowledge(config = {}) {
|
|
39
|
+
const store = ragStore({
|
|
40
|
+
model: config.model,
|
|
41
|
+
backend: config.backend,
|
|
42
|
+
branch: config.branch,
|
|
43
|
+
contentDir: resolveProjectPath(config.projectDir, config.contentDir ?? DEFAULT_CONTENT_DIR),
|
|
44
|
+
storagePath: resolveProjectPath(config.projectDir, config.storagePath ?? DEFAULT_STORAGE_PATH),
|
|
45
|
+
contentExtensions: config.contentExtensions,
|
|
46
|
+
});
|
|
47
|
+
async function index() {
|
|
48
|
+
await store.indexContentDir();
|
|
49
|
+
}
|
|
50
|
+
async function search(query, options) {
|
|
51
|
+
const normalizedQuery = normalizeKnowledgeQuery(query, config.maxQueryChars);
|
|
52
|
+
if (!normalizedQuery)
|
|
53
|
+
return [];
|
|
54
|
+
return store.search(normalizedQuery, {
|
|
55
|
+
topK: options?.topK ?? config.topK ?? DEFAULT_TOP_K,
|
|
56
|
+
threshold: options?.threshold ?? config.threshold,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
index,
|
|
61
|
+
async retrieve(query, options) {
|
|
62
|
+
const normalizedQuery = normalizeKnowledgeQuery(query, options?.maxQueryChars ?? config.maxQueryChars);
|
|
63
|
+
if (!normalizedQuery)
|
|
64
|
+
return { query: "", matches: [], context: "" };
|
|
65
|
+
const matches = await store.search(normalizedQuery, {
|
|
66
|
+
topK: options?.topK ?? config.topK ?? DEFAULT_TOP_K,
|
|
67
|
+
threshold: options?.threshold ?? config.threshold,
|
|
68
|
+
});
|
|
69
|
+
return {
|
|
70
|
+
query: normalizedQuery,
|
|
71
|
+
matches,
|
|
72
|
+
context: formatKnowledgeContext(matches),
|
|
73
|
+
};
|
|
74
|
+
},
|
|
75
|
+
search,
|
|
76
|
+
};
|
|
77
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "veryfront",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.934",
|
|
4
4
|
"description": "The simplest way to build AI-powered apps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -193,6 +193,10 @@
|
|
|
193
193
|
"import": "./esm/src/embedding/index.js",
|
|
194
194
|
"types": "./esm/src/embedding/index.d.ts"
|
|
195
195
|
},
|
|
196
|
+
"./knowledge": {
|
|
197
|
+
"import": "./esm/src/knowledge/index.js",
|
|
198
|
+
"types": "./esm/src/knowledge/index.d.ts"
|
|
199
|
+
},
|
|
196
200
|
"./extensions": {
|
|
197
201
|
"import": "./esm/src/extensions/index.js",
|
|
198
202
|
"types": "./esm/src/extensions/index.d.ts"
|