veryfront 0.1.933 → 0.1.935
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/knowledge/index.d.ts +132 -0
- package/esm/src/knowledge/index.d.ts.map +1 -0
- package/esm/src/knowledge/index.js +472 -0
- package/esm/src/platform/compat/index.d.ts +17 -0
- package/esm/src/platform/compat/index.d.ts.map +1 -0
- package/esm/src/platform/compat/index.js +22 -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.935",
|
|
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,
|
|
@@ -0,0 +1,132 @@
|
|
|
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
|
+
import type { Tool } from "../tool/types.js";
|
|
18
|
+
/** Configuration for project knowledge indexing and retrieval. */
|
|
19
|
+
export interface ProjectKnowledgeConfig {
|
|
20
|
+
/**
|
|
21
|
+
* Project root used to resolve relative local paths.
|
|
22
|
+
*
|
|
23
|
+
* Hosted Veryfront Cloud request contexts ignore this for release-backed
|
|
24
|
+
* content lookup, but local development uses it to find `knowledge/` and
|
|
25
|
+
* `data/knowledge-index.json`.
|
|
26
|
+
*/
|
|
27
|
+
projectDir?: string;
|
|
28
|
+
/**
|
|
29
|
+
* Directory containing source-controlled knowledge files.
|
|
30
|
+
*
|
|
31
|
+
* Defaults to `knowledge`.
|
|
32
|
+
*/
|
|
33
|
+
contentDir?: string;
|
|
34
|
+
/**
|
|
35
|
+
* Local JSON index path.
|
|
36
|
+
*
|
|
37
|
+
* Defaults to `data/knowledge-index.json`.
|
|
38
|
+
*/
|
|
39
|
+
storagePath?: string;
|
|
40
|
+
contentExtensions?: string[];
|
|
41
|
+
model?: string;
|
|
42
|
+
backend?: RagStoreBackend;
|
|
43
|
+
branch?: string;
|
|
44
|
+
topK?: number;
|
|
45
|
+
threshold?: number;
|
|
46
|
+
maxQueryChars?: number;
|
|
47
|
+
}
|
|
48
|
+
/** Per-call options for project knowledge retrieval. */
|
|
49
|
+
export interface ProjectKnowledgeRetrieveOptions extends RagSearchOptions {
|
|
50
|
+
maxQueryChars?: number;
|
|
51
|
+
}
|
|
52
|
+
/** Result returned from project knowledge retrieval. */
|
|
53
|
+
export interface ProjectKnowledgeResult {
|
|
54
|
+
query: string;
|
|
55
|
+
matches: RagSearchResult[];
|
|
56
|
+
context: string;
|
|
57
|
+
}
|
|
58
|
+
export interface ProjectKnowledgeLookupInput {
|
|
59
|
+
project_reference?: string;
|
|
60
|
+
query?: string;
|
|
61
|
+
cursor?: string;
|
|
62
|
+
lookup_target?: unknown;
|
|
63
|
+
limit?: number;
|
|
64
|
+
shard_count?: number;
|
|
65
|
+
shard_index?: number;
|
|
66
|
+
}
|
|
67
|
+
export interface ProjectKnowledgeLookupFrontmatterField {
|
|
68
|
+
key: string;
|
|
69
|
+
value: string;
|
|
70
|
+
}
|
|
71
|
+
export interface ProjectKnowledgeLookupItem {
|
|
72
|
+
path: string;
|
|
73
|
+
matched_fields: string[];
|
|
74
|
+
frontmatter: ProjectKnowledgeLookupFrontmatterField[];
|
|
75
|
+
}
|
|
76
|
+
export interface ProjectKnowledgeLookupPageInfo {
|
|
77
|
+
self: string | null;
|
|
78
|
+
first: string | null;
|
|
79
|
+
next: string | null;
|
|
80
|
+
prev: string | null;
|
|
81
|
+
}
|
|
82
|
+
export interface ProjectKnowledgeLookupShard {
|
|
83
|
+
shard_index: number;
|
|
84
|
+
shard_count: number;
|
|
85
|
+
total_items: number;
|
|
86
|
+
}
|
|
87
|
+
export interface ProjectKnowledgeLookupOutput {
|
|
88
|
+
query: string;
|
|
89
|
+
mode: "search" | "browse";
|
|
90
|
+
data: ProjectKnowledgeLookupItem[];
|
|
91
|
+
page_info: ProjectKnowledgeLookupPageInfo;
|
|
92
|
+
returned: number;
|
|
93
|
+
total_matches: number;
|
|
94
|
+
shard: ProjectKnowledgeLookupShard;
|
|
95
|
+
}
|
|
96
|
+
export interface CreateSearchKnowledgeToolOptions extends ProjectKnowledgeConfig {
|
|
97
|
+
id?: string;
|
|
98
|
+
description?: string;
|
|
99
|
+
}
|
|
100
|
+
export type SearchKnowledgeTool = Tool<ProjectKnowledgeLookupInput, ProjectKnowledgeLookupOutput>;
|
|
101
|
+
/** Helper for indexing and retrieving project knowledge. */
|
|
102
|
+
export interface ProjectKnowledge {
|
|
103
|
+
/**
|
|
104
|
+
* Index configured project knowledge explicitly.
|
|
105
|
+
*
|
|
106
|
+
* Keep this out of the chat request path. Use it during setup, deploy,
|
|
107
|
+
* ingestion, or another controlled lifecycle step.
|
|
108
|
+
*/
|
|
109
|
+
index(): Promise<void>;
|
|
110
|
+
/**
|
|
111
|
+
* Search the local OKF knowledge manifest using the same compact
|
|
112
|
+
* frontmatter-only response shape as Veryfront Cloud's `search_knowledge`
|
|
113
|
+
* tool. This does not build or query the embedding index.
|
|
114
|
+
*/
|
|
115
|
+
lookup(input: ProjectKnowledgeLookupInput): Promise<ProjectKnowledgeLookupOutput>;
|
|
116
|
+
retrieve(query: string, options?: ProjectKnowledgeRetrieveOptions): Promise<ProjectKnowledgeResult>;
|
|
117
|
+
search(query: string, options?: RagSearchOptions): Promise<RagSearchResult[]>;
|
|
118
|
+
}
|
|
119
|
+
/** Normalize a knowledge query before retrieval. */
|
|
120
|
+
export declare function normalizeKnowledgeQuery(query: string, maxChars?: number): string;
|
|
121
|
+
/** Format search results into a deterministic prompt context block. */
|
|
122
|
+
export declare function formatKnowledgeContext(results: RagSearchResult[]): string;
|
|
123
|
+
/**
|
|
124
|
+
* Search the local OKF knowledge manifest with the same input/output shape as
|
|
125
|
+
* Veryfront Cloud's `search_knowledge` MCP tool.
|
|
126
|
+
*/
|
|
127
|
+
export declare function searchProjectKnowledge(input: ProjectKnowledgeLookupInput, config?: ProjectKnowledgeConfig): Promise<ProjectKnowledgeLookupOutput>;
|
|
128
|
+
/** Create a local tool with the same id and response shape as hosted `search_knowledge`. */
|
|
129
|
+
export declare function createSearchKnowledgeTool(options?: CreateSearchKnowledgeToolOptions): SearchKnowledgeTool;
|
|
130
|
+
/** Create a project knowledge helper backed by the configured RAG store. */
|
|
131
|
+
export declare function projectKnowledge(config?: ProjectKnowledgeConfig): ProjectKnowledge;
|
|
132
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/src/knowledge/index.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,472 @@
|
|
|
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 { exists, readDir, readTextFile } from "../platform/compat/index.js";
|
|
18
|
+
import { extract } from "../platform/compat/std/front-matter-yaml.js";
|
|
19
|
+
import { isAbsolute, join, relative } from "../platform/compat/path/index.js";
|
|
20
|
+
import { tool } from "../tool/factory.js";
|
|
21
|
+
const DEFAULT_CONTENT_DIR = "knowledge";
|
|
22
|
+
const DEFAULT_STORAGE_PATH = "data/knowledge-index.json";
|
|
23
|
+
const DEFAULT_TOP_K = 3;
|
|
24
|
+
const DEFAULT_QUERY_MAX_CHARS = 500;
|
|
25
|
+
const DEFAULT_LOOKUP_LIMIT = 8;
|
|
26
|
+
const MAX_LOOKUP_LIMIT = 12;
|
|
27
|
+
const MAX_FRONTMATTER_FIELDS = 6;
|
|
28
|
+
const MAX_FRONTMATTER_VALUE_LENGTH = 240;
|
|
29
|
+
const KNOWLEDGE_LOOKUP_CURSOR_VERSION = 1;
|
|
30
|
+
const FRONTMATTER_FIELD_PRIORITY = [
|
|
31
|
+
"title",
|
|
32
|
+
"name",
|
|
33
|
+
"description",
|
|
34
|
+
"summary",
|
|
35
|
+
"source",
|
|
36
|
+
"source_type",
|
|
37
|
+
"added",
|
|
38
|
+
];
|
|
39
|
+
const SEARCH_KNOWLEDGE_INPUT_SCHEMA = {
|
|
40
|
+
type: "object",
|
|
41
|
+
properties: {
|
|
42
|
+
project_reference: {
|
|
43
|
+
type: "string",
|
|
44
|
+
description: "Project reference accepted for hosted/local parity.",
|
|
45
|
+
},
|
|
46
|
+
query: {
|
|
47
|
+
type: "string",
|
|
48
|
+
description: "Knowledge query to match against OKF frontmatter.",
|
|
49
|
+
},
|
|
50
|
+
cursor: {
|
|
51
|
+
type: "string",
|
|
52
|
+
description: "Cursor from a previous search_knowledge response.",
|
|
53
|
+
},
|
|
54
|
+
lookup_target: {
|
|
55
|
+
type: "object",
|
|
56
|
+
additionalProperties: true,
|
|
57
|
+
description: "Hosted lookup target accepted for API parity and ignored locally.",
|
|
58
|
+
},
|
|
59
|
+
limit: {
|
|
60
|
+
type: "integer",
|
|
61
|
+
description: "Maximum number of manifest entries to return.",
|
|
62
|
+
},
|
|
63
|
+
shard_count: {
|
|
64
|
+
type: "integer",
|
|
65
|
+
description: "Optional shard count for splitting large manifests.",
|
|
66
|
+
},
|
|
67
|
+
shard_index: {
|
|
68
|
+
type: "integer",
|
|
69
|
+
description: "Zero-based shard index.",
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
additionalProperties: false,
|
|
73
|
+
};
|
|
74
|
+
function resolveProjectPath(projectDir, path) {
|
|
75
|
+
if (!projectDir || isAbsolute(path))
|
|
76
|
+
return path;
|
|
77
|
+
return join(projectDir, path);
|
|
78
|
+
}
|
|
79
|
+
function toPosixPath(path) {
|
|
80
|
+
return path.replace(/\\/g, "/");
|
|
81
|
+
}
|
|
82
|
+
function stripTrailingSlash(path) {
|
|
83
|
+
return toPosixPath(path).replace(/\/+$/, "");
|
|
84
|
+
}
|
|
85
|
+
function buildManifestPath(config, absolutePath) {
|
|
86
|
+
const contentDir = config.contentDir ?? DEFAULT_CONTENT_DIR;
|
|
87
|
+
const contentDirPath = resolveProjectPath(config.projectDir, contentDir);
|
|
88
|
+
const relativeToContent = toPosixPath(relative(contentDirPath, absolutePath));
|
|
89
|
+
if (!isAbsolute(contentDir)) {
|
|
90
|
+
const normalizedContentDir = stripTrailingSlash(contentDir).replace(/^\.\//, "");
|
|
91
|
+
return `${normalizedContentDir}/${relativeToContent}`;
|
|
92
|
+
}
|
|
93
|
+
if (config.projectDir) {
|
|
94
|
+
return toPosixPath(relative(config.projectDir, absolutePath));
|
|
95
|
+
}
|
|
96
|
+
return relativeToContent;
|
|
97
|
+
}
|
|
98
|
+
async function collectMarkdownFiles(dir) {
|
|
99
|
+
if (!(await exists(dir)))
|
|
100
|
+
return [];
|
|
101
|
+
const files = [];
|
|
102
|
+
for await (const entry of readDir(dir)) {
|
|
103
|
+
const entryPath = join(dir, entry.name);
|
|
104
|
+
if (entry.isDirectory) {
|
|
105
|
+
files.push(...await collectMarkdownFiles(entryPath));
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
if (entry.isFile && entry.name.endsWith(".md")) {
|
|
109
|
+
files.push(entryPath);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return files;
|
|
113
|
+
}
|
|
114
|
+
function normalizeText(value) {
|
|
115
|
+
return value
|
|
116
|
+
.normalize("NFKD")
|
|
117
|
+
.replace(/[\u0300-\u036f]/g, "")
|
|
118
|
+
.toLowerCase()
|
|
119
|
+
.replace(/[^a-z0-9]+/g, " ")
|
|
120
|
+
.trim();
|
|
121
|
+
}
|
|
122
|
+
function tokenize(value) {
|
|
123
|
+
return [
|
|
124
|
+
...new Set(normalizeText(value)
|
|
125
|
+
.split(/\s+/)
|
|
126
|
+
.filter((token) => token.length >= 2)),
|
|
127
|
+
];
|
|
128
|
+
}
|
|
129
|
+
function hashPath(value) {
|
|
130
|
+
let hash = 5381;
|
|
131
|
+
for (const char of value) {
|
|
132
|
+
hash = ((hash * 33) ^ char.charCodeAt(0)) >>> 0;
|
|
133
|
+
}
|
|
134
|
+
return hash;
|
|
135
|
+
}
|
|
136
|
+
function collapseFrontmatterValue(value) {
|
|
137
|
+
if (value == null)
|
|
138
|
+
return null;
|
|
139
|
+
let stringValue = "";
|
|
140
|
+
if (typeof value === "string") {
|
|
141
|
+
stringValue = value;
|
|
142
|
+
}
|
|
143
|
+
else if (typeof value === "number" || typeof value === "boolean") {
|
|
144
|
+
stringValue = String(value);
|
|
145
|
+
}
|
|
146
|
+
else if (Array.isArray(value)) {
|
|
147
|
+
stringValue = value
|
|
148
|
+
.map((item) => collapseFrontmatterValue(item))
|
|
149
|
+
.filter((item) => typeof item === "string" && item.length > 0)
|
|
150
|
+
.join(", ");
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
try {
|
|
154
|
+
stringValue = JSON.stringify(value);
|
|
155
|
+
}
|
|
156
|
+
catch {
|
|
157
|
+
stringValue = String(value);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
const collapsed = stringValue.replace(/\s+/g, " ").trim();
|
|
161
|
+
return collapsed.length > 0 ? collapsed : null;
|
|
162
|
+
}
|
|
163
|
+
function truncateFrontmatterValue(value) {
|
|
164
|
+
if (value.length <= MAX_FRONTMATTER_VALUE_LENGTH)
|
|
165
|
+
return value;
|
|
166
|
+
return `${value.slice(0, MAX_FRONTMATTER_VALUE_LENGTH - 3)}...`;
|
|
167
|
+
}
|
|
168
|
+
function compareFrontmatterFields(left, right) {
|
|
169
|
+
const leftPriority = FRONTMATTER_FIELD_PRIORITY.indexOf(left.key);
|
|
170
|
+
const rightPriority = FRONTMATTER_FIELD_PRIORITY.indexOf(right.key);
|
|
171
|
+
if (leftPriority !== rightPriority) {
|
|
172
|
+
if (leftPriority === -1)
|
|
173
|
+
return 1;
|
|
174
|
+
if (rightPriority === -1)
|
|
175
|
+
return -1;
|
|
176
|
+
return leftPriority - rightPriority;
|
|
177
|
+
}
|
|
178
|
+
return left.key.localeCompare(right.key);
|
|
179
|
+
}
|
|
180
|
+
function collectFrontmatter(frontmatter) {
|
|
181
|
+
return Object.entries(frontmatter)
|
|
182
|
+
.map(([key, rawValue]) => {
|
|
183
|
+
const value = collapseFrontmatterValue(rawValue);
|
|
184
|
+
return value ? { key, value } : null;
|
|
185
|
+
})
|
|
186
|
+
.filter((entry) => entry !== null)
|
|
187
|
+
.sort(compareFrontmatterFields);
|
|
188
|
+
}
|
|
189
|
+
function sanitizeFrontmatter(frontmatter) {
|
|
190
|
+
const searchableFrontmatter = collectFrontmatter(frontmatter);
|
|
191
|
+
return {
|
|
192
|
+
frontmatter: searchableFrontmatter.slice(0, MAX_FRONTMATTER_FIELDS).map((field) => ({
|
|
193
|
+
key: field.key,
|
|
194
|
+
value: truncateFrontmatterValue(field.value),
|
|
195
|
+
})),
|
|
196
|
+
searchableFrontmatter,
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
function toSearchableEntry(entry) {
|
|
200
|
+
return {
|
|
201
|
+
...entry,
|
|
202
|
+
normalizedPath: normalizeText(entry.path),
|
|
203
|
+
searchableFrontmatter: entry.searchableFrontmatter.map((field) => ({
|
|
204
|
+
...field,
|
|
205
|
+
normalizedKey: normalizeText(field.key),
|
|
206
|
+
normalizedValue: normalizeText(field.value),
|
|
207
|
+
})),
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
function encodeCursor(state) {
|
|
211
|
+
const bytes = new TextEncoder().encode(JSON.stringify(state));
|
|
212
|
+
let binary = "";
|
|
213
|
+
for (const byte of bytes)
|
|
214
|
+
binary += String.fromCharCode(byte);
|
|
215
|
+
return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
216
|
+
}
|
|
217
|
+
function decodeCursor(cursor) {
|
|
218
|
+
try {
|
|
219
|
+
const padded = cursor.replace(/-/g, "+").replace(/_/g, "/").padEnd(Math.ceil(cursor.length / 4) * 4, "=");
|
|
220
|
+
const binary = atob(padded);
|
|
221
|
+
const bytes = Uint8Array.from(binary, (char) => char.charCodeAt(0));
|
|
222
|
+
const parsed = JSON.parse(new TextDecoder().decode(bytes));
|
|
223
|
+
if (parsed.version !== KNOWLEDGE_LOOKUP_CURSOR_VERSION ||
|
|
224
|
+
typeof parsed.query !== "string" ||
|
|
225
|
+
typeof parsed.offset !== "number" ||
|
|
226
|
+
typeof parsed.limit !== "number" ||
|
|
227
|
+
typeof parsed.shardCount !== "number" ||
|
|
228
|
+
typeof parsed.shardIndex !== "number") {
|
|
229
|
+
throw new Error("Invalid cursor payload");
|
|
230
|
+
}
|
|
231
|
+
if (parsed.shardIndex < 0 || parsed.shardIndex >= parsed.shardCount) {
|
|
232
|
+
throw new Error("Cursor shard_index must be within shard_count");
|
|
233
|
+
}
|
|
234
|
+
return {
|
|
235
|
+
version: parsed.version,
|
|
236
|
+
query: parsed.query,
|
|
237
|
+
offset: parsed.offset,
|
|
238
|
+
limit: parsed.limit,
|
|
239
|
+
shardCount: parsed.shardCount,
|
|
240
|
+
shardIndex: parsed.shardIndex,
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
catch (error) {
|
|
244
|
+
const message = error instanceof Error ? error.message : "Could not decode cursor";
|
|
245
|
+
throw new Error(`Invalid knowledge lookup cursor: ${message}`);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
function scoreEntry(entry, query, queryTokens) {
|
|
249
|
+
const matchedFields = new Set();
|
|
250
|
+
const normalizedQuery = normalizeText(query);
|
|
251
|
+
let score = 0;
|
|
252
|
+
if (normalizedQuery && entry.normalizedPath.includes(normalizedQuery)) {
|
|
253
|
+
score += 40;
|
|
254
|
+
matchedFields.add("path");
|
|
255
|
+
}
|
|
256
|
+
for (const field of entry.searchableFrontmatter) {
|
|
257
|
+
if (normalizedQuery && field.normalizedValue.includes(normalizedQuery)) {
|
|
258
|
+
score += 28;
|
|
259
|
+
matchedFields.add(field.key);
|
|
260
|
+
}
|
|
261
|
+
if (normalizedQuery && field.normalizedKey.includes(normalizedQuery)) {
|
|
262
|
+
score += 12;
|
|
263
|
+
matchedFields.add(field.key);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
if (queryTokens.length > 1) {
|
|
267
|
+
for (const token of queryTokens) {
|
|
268
|
+
if (entry.normalizedPath.includes(token)) {
|
|
269
|
+
score += 10;
|
|
270
|
+
matchedFields.add("path");
|
|
271
|
+
}
|
|
272
|
+
for (const field of entry.searchableFrontmatter) {
|
|
273
|
+
if (field.normalizedValue.includes(token)) {
|
|
274
|
+
score += 7;
|
|
275
|
+
matchedFields.add(field.key);
|
|
276
|
+
}
|
|
277
|
+
if (field.normalizedKey.includes(token)) {
|
|
278
|
+
score += 4;
|
|
279
|
+
matchedFields.add(field.key);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
return {
|
|
285
|
+
score,
|
|
286
|
+
matchedFields: [...matchedFields].sort((left, right) => left.localeCompare(right)),
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
async function getProjectKnowledgeManifest(config) {
|
|
290
|
+
const contentDir = resolveProjectPath(config.projectDir, config.contentDir ?? DEFAULT_CONTENT_DIR);
|
|
291
|
+
const files = (await collectMarkdownFiles(contentDir)).sort((left, right) => buildManifestPath(config, left).localeCompare(buildManifestPath(config, right)));
|
|
292
|
+
const manifest = [];
|
|
293
|
+
for (const file of files) {
|
|
294
|
+
let parsedFrontmatter = {};
|
|
295
|
+
try {
|
|
296
|
+
parsedFrontmatter = extract(await readTextFile(file)).attrs;
|
|
297
|
+
}
|
|
298
|
+
catch {
|
|
299
|
+
parsedFrontmatter = {};
|
|
300
|
+
}
|
|
301
|
+
manifest.push({
|
|
302
|
+
path: buildManifestPath(config, file),
|
|
303
|
+
...sanitizeFrontmatter(parsedFrontmatter),
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
return manifest;
|
|
307
|
+
}
|
|
308
|
+
function lookupKnowledgeManifest(manifest, input) {
|
|
309
|
+
const cursorState = input.cursor ? decodeCursor(input.cursor) : null;
|
|
310
|
+
const providedQuery = input.query?.trim() ?? "";
|
|
311
|
+
const resolvedQuery = (cursorState?.query ?? providedQuery).trim();
|
|
312
|
+
if (!resolvedQuery) {
|
|
313
|
+
throw new Error("search_knowledge requires a non-empty query");
|
|
314
|
+
}
|
|
315
|
+
if (cursorState && providedQuery && providedQuery !== cursorState.query) {
|
|
316
|
+
throw new Error("search_knowledge cursor query mismatch");
|
|
317
|
+
}
|
|
318
|
+
const resolvedShardCount = cursorState?.shardCount ?? input.shard_count ?? 1;
|
|
319
|
+
const resolvedShardIndex = cursorState?.shardIndex ?? input.shard_index ?? 0;
|
|
320
|
+
if (resolvedShardCount < 1) {
|
|
321
|
+
throw new Error("search_knowledge shard_count must be at least 1");
|
|
322
|
+
}
|
|
323
|
+
if (resolvedShardIndex < 0 || resolvedShardIndex >= resolvedShardCount) {
|
|
324
|
+
throw new Error("search_knowledge shard_index must be within shard_count");
|
|
325
|
+
}
|
|
326
|
+
const resolvedLimit = Math.min(Math.max(cursorState?.limit ?? input.limit ?? DEFAULT_LOOKUP_LIMIT, 1), MAX_LOOKUP_LIMIT);
|
|
327
|
+
const resolvedOffset = Math.max(cursorState?.offset ?? 0, 0);
|
|
328
|
+
const queryTokens = tokenize(resolvedQuery);
|
|
329
|
+
const shardEntries = manifest
|
|
330
|
+
.filter((entry) => hashPath(entry.path) % resolvedShardCount === resolvedShardIndex)
|
|
331
|
+
.map(toSearchableEntry);
|
|
332
|
+
const scoredEntries = shardEntries
|
|
333
|
+
.map((entry) => ({
|
|
334
|
+
entry,
|
|
335
|
+
...scoreEntry(entry, resolvedQuery, queryTokens),
|
|
336
|
+
}))
|
|
337
|
+
.sort((left, right) => {
|
|
338
|
+
if (right.score !== left.score)
|
|
339
|
+
return right.score - left.score;
|
|
340
|
+
return left.entry.path.localeCompare(right.entry.path);
|
|
341
|
+
});
|
|
342
|
+
const hasScoredMatches = scoredEntries.some((entry) => entry.score > 0);
|
|
343
|
+
const mode = hasScoredMatches ? "search" : "browse";
|
|
344
|
+
const orderedEntries = hasScoredMatches
|
|
345
|
+
? scoredEntries.filter((entry) => entry.score > 0)
|
|
346
|
+
: scoredEntries;
|
|
347
|
+
const pageEntries = orderedEntries.slice(resolvedOffset, resolvedOffset + resolvedLimit);
|
|
348
|
+
const nextOffset = resolvedOffset + pageEntries.length;
|
|
349
|
+
const hasMore = nextOffset < orderedEntries.length;
|
|
350
|
+
const nextCursor = hasMore
|
|
351
|
+
? encodeCursor({
|
|
352
|
+
version: KNOWLEDGE_LOOKUP_CURSOR_VERSION,
|
|
353
|
+
query: resolvedQuery,
|
|
354
|
+
offset: nextOffset,
|
|
355
|
+
limit: resolvedLimit,
|
|
356
|
+
shardCount: resolvedShardCount,
|
|
357
|
+
shardIndex: resolvedShardIndex,
|
|
358
|
+
})
|
|
359
|
+
: null;
|
|
360
|
+
return {
|
|
361
|
+
query: resolvedQuery,
|
|
362
|
+
mode,
|
|
363
|
+
data: pageEntries.map(({ entry, matchedFields }) => ({
|
|
364
|
+
path: entry.path,
|
|
365
|
+
matched_fields: matchedFields,
|
|
366
|
+
frontmatter: entry.frontmatter,
|
|
367
|
+
})),
|
|
368
|
+
page_info: {
|
|
369
|
+
self: input.cursor ?? null,
|
|
370
|
+
first: null,
|
|
371
|
+
next: nextCursor,
|
|
372
|
+
prev: null,
|
|
373
|
+
},
|
|
374
|
+
returned: pageEntries.length,
|
|
375
|
+
total_matches: orderedEntries.length,
|
|
376
|
+
shard: {
|
|
377
|
+
shard_index: resolvedShardIndex,
|
|
378
|
+
shard_count: resolvedShardCount,
|
|
379
|
+
total_items: shardEntries.length,
|
|
380
|
+
},
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
function coerceSearchKnowledgeInput(input) {
|
|
384
|
+
if (input === null || typeof input !== "object" || Array.isArray(input)) {
|
|
385
|
+
throw new Error("search_knowledge input must be an object");
|
|
386
|
+
}
|
|
387
|
+
const value = input;
|
|
388
|
+
return {
|
|
389
|
+
project_reference: typeof value.project_reference === "string"
|
|
390
|
+
? value.project_reference
|
|
391
|
+
: undefined,
|
|
392
|
+
query: typeof value.query === "string" ? value.query : undefined,
|
|
393
|
+
cursor: typeof value.cursor === "string" ? value.cursor : undefined,
|
|
394
|
+
lookup_target: value.lookup_target,
|
|
395
|
+
limit: typeof value.limit === "number" ? value.limit : undefined,
|
|
396
|
+
shard_count: typeof value.shard_count === "number" ? value.shard_count : undefined,
|
|
397
|
+
shard_index: typeof value.shard_index === "number" ? value.shard_index : undefined,
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
/** Normalize a knowledge query before retrieval. */
|
|
401
|
+
export function normalizeKnowledgeQuery(query, maxChars = DEFAULT_QUERY_MAX_CHARS) {
|
|
402
|
+
return query.replace(/\s+/g, " ").trim().slice(0, maxChars);
|
|
403
|
+
}
|
|
404
|
+
/** Format search results into a deterministic prompt context block. */
|
|
405
|
+
export function formatKnowledgeContext(results) {
|
|
406
|
+
return results
|
|
407
|
+
.map((result) => `[${result.title}] (score: ${result.score.toFixed(2)})\n${result.text}`)
|
|
408
|
+
.join("\n\n---\n\n");
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* Search the local OKF knowledge manifest with the same input/output shape as
|
|
412
|
+
* Veryfront Cloud's `search_knowledge` MCP tool.
|
|
413
|
+
*/
|
|
414
|
+
export async function searchProjectKnowledge(input, config = {}) {
|
|
415
|
+
const manifest = await getProjectKnowledgeManifest(config);
|
|
416
|
+
return lookupKnowledgeManifest(manifest, input);
|
|
417
|
+
}
|
|
418
|
+
/** Create a local tool with the same id and response shape as hosted `search_knowledge`. */
|
|
419
|
+
export function createSearchKnowledgeTool(options = {}) {
|
|
420
|
+
const { id = "search_knowledge", description, ...config } = options;
|
|
421
|
+
return tool({
|
|
422
|
+
id,
|
|
423
|
+
description: description ??
|
|
424
|
+
"Retrieve a compact, cursor-based slice of the local project knowledge manifest.",
|
|
425
|
+
inputSchema: SEARCH_KNOWLEDGE_INPUT_SCHEMA,
|
|
426
|
+
execute: (input) => searchProjectKnowledge(coerceSearchKnowledgeInput(input), config),
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
/** Create a project knowledge helper backed by the configured RAG store. */
|
|
430
|
+
export function projectKnowledge(config = {}) {
|
|
431
|
+
const store = ragStore({
|
|
432
|
+
model: config.model,
|
|
433
|
+
backend: config.backend,
|
|
434
|
+
branch: config.branch,
|
|
435
|
+
contentDir: resolveProjectPath(config.projectDir, config.contentDir ?? DEFAULT_CONTENT_DIR),
|
|
436
|
+
storagePath: resolveProjectPath(config.projectDir, config.storagePath ?? DEFAULT_STORAGE_PATH),
|
|
437
|
+
contentExtensions: config.contentExtensions,
|
|
438
|
+
});
|
|
439
|
+
async function index() {
|
|
440
|
+
await store.indexContentDir();
|
|
441
|
+
}
|
|
442
|
+
async function search(query, options) {
|
|
443
|
+
const normalizedQuery = normalizeKnowledgeQuery(query, config.maxQueryChars);
|
|
444
|
+
if (!normalizedQuery)
|
|
445
|
+
return [];
|
|
446
|
+
return store.search(normalizedQuery, {
|
|
447
|
+
topK: options?.topK ?? config.topK ?? DEFAULT_TOP_K,
|
|
448
|
+
threshold: options?.threshold ?? config.threshold,
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
return {
|
|
452
|
+
index,
|
|
453
|
+
lookup(input) {
|
|
454
|
+
return searchProjectKnowledge(input, config);
|
|
455
|
+
},
|
|
456
|
+
async retrieve(query, options) {
|
|
457
|
+
const normalizedQuery = normalizeKnowledgeQuery(query, options?.maxQueryChars ?? config.maxQueryChars);
|
|
458
|
+
if (!normalizedQuery)
|
|
459
|
+
return { query: "", matches: [], context: "" };
|
|
460
|
+
const matches = await store.search(normalizedQuery, {
|
|
461
|
+
topK: options?.topK ?? config.topK ?? DEFAULT_TOP_K,
|
|
462
|
+
threshold: options?.threshold ?? config.threshold,
|
|
463
|
+
});
|
|
464
|
+
return {
|
|
465
|
+
query: normalizedQuery,
|
|
466
|
+
matches,
|
|
467
|
+
context: formatKnowledgeContext(matches),
|
|
468
|
+
};
|
|
469
|
+
},
|
|
470
|
+
search,
|
|
471
|
+
};
|
|
472
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Platform Compat
|
|
3
|
+
*
|
|
4
|
+
* @module platform/compat
|
|
5
|
+
*/
|
|
6
|
+
export { createFileSystem, exists, type FileSystem, isNotFoundError, makeTempDir, mkdir, readDir, readTextFile, remove, stat, symlink, writeFile, writeTextFile, } from "./fs.js";
|
|
7
|
+
export { createKVStore, MemoryKv, openKv, polyfillDenoKv } from "./kv/index.js";
|
|
8
|
+
export { SqliteKv } from "./kv/index.js";
|
|
9
|
+
export type { Kv, KvEntry, KvListOptions, SqliteDatabase } from "./kv/index.js";
|
|
10
|
+
export { chdir, cwd, deleteEnv, env, execPath, exit, getArgs, getEnv, getEnvBoolean, getEnvNumber, getEnvOverlayStorage, getEnvString, getOsType, getRuntimeVersion, getStdout, getTerminalSize, isInteractive, isStdoutTTY, memoryUsage, onGlobalError, onSignal, pid, promptSync, runCommand, setEnv, unrefTimer, uptime, writeStdout, writeStdoutAsync, } from "./process.js";
|
|
11
|
+
export type { CommandOptions, CommandResult, EnvBooleanOptions } from "./process.js";
|
|
12
|
+
export { isBrowserEnvironment, isBun, isCloudflare, isDeno, isDenoCompiled, isNode, isNodeRuntime, isServerEnvironment, } from "./runtime.js";
|
|
13
|
+
export { createEscapeBuffer, type EscapeBuffer, getStdinReader, setRawMode, type StdinReader, waitForEnterOrExit, waitForKeypress, } from "./stdin.js";
|
|
14
|
+
export { dynamicImport } from "./dynamic-import.js";
|
|
15
|
+
export { importClaudeAgentSDK, importKreuzberg, importTransformers } from "./opaque-deps.js";
|
|
16
|
+
export { basename, dirname, extname, fromFileUrl, isAbsolute, join, relative, resolve, sep, } from "./path/index.js";
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/src/platform/compat/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EACL,gBAAgB,EAChB,MAAM,EACN,KAAK,UAAU,EACf,eAAe,EACf,WAAW,EACX,KAAK,EACL,OAAO,EACP,YAAY,EACZ,MAAM,EACN,IAAI,EACJ,OAAO,EACP,SAAS,EACT,aAAa,GACd,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAChF,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,YAAY,EAAE,EAAE,EAAE,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAGhF,OAAO,EACL,KAAK,EACL,GAAG,EACH,SAAS,EACT,GAAG,EACH,QAAQ,EACR,IAAI,EACJ,OAAO,EACP,MAAM,EACN,aAAa,EACb,YAAY,EACZ,oBAAoB,EACpB,YAAY,EACZ,SAAS,EACT,iBAAiB,EACjB,SAAS,EACT,eAAe,EACf,aAAa,EACb,WAAW,EACX,WAAW,EACX,aAAa,EACb,QAAQ,EACR,GAAG,EACH,UAAU,EACV,UAAU,EACV,MAAM,EACN,UAAU,EACV,MAAM,EACN,WAAW,EACX,gBAAgB,GACjB,MAAM,cAAc,CAAC;AACtB,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAGrF,OAAO,EACL,oBAAoB,EACpB,KAAK,EACL,YAAY,EACZ,MAAM,EACN,cAAc,EACd,MAAM,EACN,aAAa,EACb,mBAAmB,GACpB,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,kBAAkB,EAClB,KAAK,YAAY,EACjB,cAAc,EACd,UAAU,EACV,KAAK,WAAW,EAChB,kBAAkB,EAClB,eAAe,GAChB,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAGpD,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAG7F,OAAO,EACL,QAAQ,EACR,OAAO,EACP,OAAO,EACP,WAAW,EACX,UAAU,EACV,IAAI,EACJ,QAAQ,EACR,OAAO,EACP,GAAG,GACJ,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Platform Compat
|
|
3
|
+
*
|
|
4
|
+
* @module platform/compat
|
|
5
|
+
*/
|
|
6
|
+
// Compat: filesystem
|
|
7
|
+
export { createFileSystem, exists, isNotFoundError, makeTempDir, mkdir, readDir, readTextFile, remove, stat, symlink, writeFile, writeTextFile, } from "./fs.js";
|
|
8
|
+
// Compat: KV store
|
|
9
|
+
export { createKVStore, MemoryKv, openKv, polyfillDenoKv } from "./kv/index.js";
|
|
10
|
+
export { SqliteKv } from "./kv/index.js";
|
|
11
|
+
// Compat: process
|
|
12
|
+
export { chdir, cwd, deleteEnv, env, execPath, exit, getArgs, getEnv, getEnvBoolean, getEnvNumber, getEnvOverlayStorage, getEnvString, getOsType, getRuntimeVersion, getStdout, getTerminalSize, isInteractive, isStdoutTTY, memoryUsage, onGlobalError, onSignal, pid, promptSync, runCommand, setEnv, unrefTimer, uptime, writeStdout, writeStdoutAsync, } from "./process.js";
|
|
13
|
+
// Compat: runtime detection
|
|
14
|
+
export { isBrowserEnvironment, isBun, isCloudflare, isDeno, isDenoCompiled, isNode, isNodeRuntime, isServerEnvironment, } from "./runtime.js";
|
|
15
|
+
// Compat: stdin
|
|
16
|
+
export { createEscapeBuffer, getStdinReader, setRawMode, waitForEnterOrExit, waitForKeypress, } from "./stdin.js";
|
|
17
|
+
// Compat: dynamic import helper (hides specifiers from static analysis / deno compile)
|
|
18
|
+
export { dynamicImport } from "./dynamic-import.js";
|
|
19
|
+
// Compat: dynamic imports for optional deps (opaque) and platform-split deps (kreuzberg)
|
|
20
|
+
export { importClaudeAgentSDK, importKreuzberg, importTransformers } from "./opaque-deps.js";
|
|
21
|
+
// Compat: path
|
|
22
|
+
export { basename, dirname, extname, fromFileUrl, isAbsolute, join, relative, resolve, sep, } from "./path/index.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "veryfront",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.935",
|
|
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"
|