rax-flow-core 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/cache/semantic-cache.d.ts +10 -0
- package/dist/cache/semantic-cache.d.ts.map +1 -0
- package/dist/cache/semantic-cache.js +50 -0
- package/dist/cache/semantic-cache.js.map +1 -0
- package/dist/governance/policies/pii-policy.d.ts +37 -0
- package/dist/governance/policies/pii-policy.d.ts.map +1 -0
- package/dist/governance/policies/pii-policy.js +177 -0
- package/dist/governance/policies/pii-policy.js.map +1 -0
- package/dist/graph/workflow-graph.d.ts +5 -0
- package/dist/graph/workflow-graph.d.ts.map +1 -0
- package/dist/graph/workflow-graph.js +38 -0
- package/dist/graph/workflow-graph.js.map +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/memory/graph-memory.d.ts +46 -0
- package/dist/memory/graph-memory.d.ts.map +1 -0
- package/dist/memory/graph-memory.js +122 -0
- package/dist/memory/graph-memory.js.map +1 -0
- package/dist/memory/local-vector-store.d.ts +36 -0
- package/dist/memory/local-vector-store.d.ts.map +1 -0
- package/dist/memory/local-vector-store.js +125 -0
- package/dist/memory/local-vector-store.js.map +1 -0
- package/dist/memory/memory-manager.d.ts +42 -0
- package/dist/memory/memory-manager.d.ts.map +1 -0
- package/dist/memory/memory-manager.js +98 -0
- package/dist/memory/memory-manager.js.map +1 -0
- package/dist/metrics/metrics-engine.d.ts +13 -0
- package/dist/metrics/metrics-engine.d.ts.map +1 -0
- package/dist/metrics/metrics-engine.js +27 -0
- package/dist/metrics/metrics-engine.js.map +1 -0
- package/dist/orchestrator/blueprint-committer.d.ts +69 -0
- package/dist/orchestrator/blueprint-committer.d.ts.map +1 -0
- package/dist/orchestrator/blueprint-committer.js +305 -0
- package/dist/orchestrator/blueprint-committer.js.map +1 -0
- package/dist/orchestrator/core-orchestrator.d.ts +168 -0
- package/dist/orchestrator/core-orchestrator.d.ts.map +1 -0
- package/dist/orchestrator/core-orchestrator.js +451 -0
- package/dist/orchestrator/core-orchestrator.js.map +1 -0
- package/dist/orchestrator/decomposition-engine.d.ts +41 -0
- package/dist/orchestrator/decomposition-engine.d.ts.map +1 -0
- package/dist/orchestrator/decomposition-engine.js +133 -0
- package/dist/orchestrator/decomposition-engine.js.map +1 -0
- package/dist/orchestrator/decomposition.d.ts +10 -0
- package/dist/orchestrator/decomposition.d.ts.map +1 -0
- package/dist/orchestrator/decomposition.js +15 -0
- package/dist/orchestrator/decomposition.js.map +1 -0
- package/dist/orchestrator/default-workflow.d.ts +59 -0
- package/dist/orchestrator/default-workflow.d.ts.map +1 -0
- package/dist/orchestrator/default-workflow.js +221 -0
- package/dist/orchestrator/default-workflow.js.map +1 -0
- package/dist/orchestrator/dynamic-planner.d.ts +46 -0
- package/dist/orchestrator/dynamic-planner.d.ts.map +1 -0
- package/dist/orchestrator/dynamic-planner.js +232 -0
- package/dist/orchestrator/dynamic-planner.js.map +1 -0
- package/dist/orchestrator/kernel-bridge.d.ts +57 -0
- package/dist/orchestrator/kernel-bridge.d.ts.map +1 -0
- package/dist/orchestrator/kernel-bridge.js +211 -0
- package/dist/orchestrator/kernel-bridge.js.map +1 -0
- package/dist/orchestrator/mutation-applier.d.ts +47 -0
- package/dist/orchestrator/mutation-applier.d.ts.map +1 -0
- package/dist/orchestrator/mutation-applier.js +253 -0
- package/dist/orchestrator/mutation-applier.js.map +1 -0
- package/dist/orchestrator/routing.d.ts +4 -0
- package/dist/orchestrator/routing.d.ts.map +1 -0
- package/dist/orchestrator/routing.js +41 -0
- package/dist/orchestrator/routing.js.map +1 -0
- package/dist/orchestrator/verify-fix.d.ts +79 -0
- package/dist/orchestrator/verify-fix.d.ts.map +1 -0
- package/dist/orchestrator/verify-fix.js +153 -0
- package/dist/orchestrator/verify-fix.js.map +1 -0
- package/dist/plugins/governance-plugin.d.ts +43 -0
- package/dist/plugins/governance-plugin.d.ts.map +1 -0
- package/dist/plugins/governance-plugin.js +88 -0
- package/dist/plugins/governance-plugin.js.map +1 -0
- package/dist/plugins/long-term-memory-plugin.d.ts +31 -0
- package/dist/plugins/long-term-memory-plugin.d.ts.map +1 -0
- package/dist/plugins/long-term-memory-plugin.js +67 -0
- package/dist/plugins/long-term-memory-plugin.js.map +1 -0
- package/dist/plugins/plugin-system.d.ts +29 -0
- package/dist/plugins/plugin-system.d.ts.map +1 -0
- package/dist/plugins/plugin-system.js +22 -0
- package/dist/plugins/plugin-system.js.map +1 -0
- package/dist/recovery/error-recovery.d.ts +15 -0
- package/dist/recovery/error-recovery.d.ts.map +1 -0
- package/dist/recovery/error-recovery.js +12 -0
- package/dist/recovery/error-recovery.js.map +1 -0
- package/dist/runtime/concurrency-scheduler.d.ts +2 -0
- package/dist/runtime/concurrency-scheduler.d.ts.map +1 -0
- package/dist/runtime/concurrency-scheduler.js +18 -0
- package/dist/runtime/concurrency-scheduler.js.map +1 -0
- package/dist/runtime/runtime-events.d.ts +59 -0
- package/dist/runtime/runtime-events.d.ts.map +1 -0
- package/dist/runtime/runtime-events.js +12 -0
- package/dist/runtime/runtime-events.js.map +1 -0
- package/dist/types/contracts.d.ts +127 -0
- package/dist/types/contracts.d.ts.map +1 -0
- package/dist/types/contracts.js +2 -0
- package/dist/types/contracts.js.map +1 -0
- package/dist/validator/structured-output-validator.d.ts +10 -0
- package/dist/validator/structured-output-validator.d.ts.map +1 -0
- package/dist/validator/structured-output-validator.js +19 -0
- package/dist/validator/structured-output-validator.js.map +1 -0
- package/package.json +18 -0
- package/src/cache/semantic-cache.ts +64 -0
- package/src/governance/policies/pii-policy.ts +213 -0
- package/src/graph/workflow-graph.ts +41 -0
- package/src/index.ts +25 -0
- package/src/memory/graph-memory.ts +150 -0
- package/src/memory/local-vector-store.ts +129 -0
- package/src/memory/memory-manager.ts +126 -0
- package/src/metrics/metrics-engine.ts +39 -0
- package/src/orchestrator/blueprint-committer.ts +351 -0
- package/src/orchestrator/core-orchestrator.ts +582 -0
- package/src/orchestrator/decomposition-engine.ts +165 -0
- package/src/orchestrator/decomposition.ts +25 -0
- package/src/orchestrator/default-workflow.ts +269 -0
- package/src/orchestrator/dynamic-planner.ts +277 -0
- package/src/orchestrator/kernel-bridge.ts +251 -0
- package/src/orchestrator/mutation-applier.ts +279 -0
- package/src/orchestrator/routing.ts +44 -0
- package/src/orchestrator/verify-fix.ts +218 -0
- package/src/plugins/governance-plugin.ts +106 -0
- package/src/plugins/long-term-memory-plugin.ts +72 -0
- package/src/plugins/plugin-system.ts +34 -0
- package/src/recovery/error-recovery.ts +23 -0
- package/src/runtime/concurrency-scheduler.ts +18 -0
- package/src/runtime/runtime-events.ts +27 -0
- package/src/types/contracts.ts +159 -0
- package/src/validator/structured-output-validator.ts +20 -0
- package/tsconfig.json +17 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare class SemanticCache {
|
|
2
|
+
private readonly store;
|
|
3
|
+
get<T>(key: string, ttlMs?: number): T | undefined;
|
|
4
|
+
set<T>(key: string, value: T): void;
|
|
5
|
+
makeKey(intent: string, prompt: string): string;
|
|
6
|
+
loadFromFile(filePath: string): Promise<void>;
|
|
7
|
+
saveToFile(filePath: string): Promise<void>;
|
|
8
|
+
clear(): void;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=semantic-cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"semantic-cache.d.ts","sourceRoot":"","sources":["../../src/cache/semantic-cache.ts"],"names":[],"mappings":"AAcA,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA0C;IAEhE,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS;IAUlD,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI;IAInC,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM;IAKzC,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAc7C,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAUjD,KAAK,IAAI,IAAI;CAGd"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
export class SemanticCache {
|
|
4
|
+
store = new Map();
|
|
5
|
+
get(key, ttlMs) {
|
|
6
|
+
const entry = this.store.get(key);
|
|
7
|
+
if (!entry)
|
|
8
|
+
return undefined;
|
|
9
|
+
if (ttlMs && Date.now() - entry.createdAt > ttlMs) {
|
|
10
|
+
this.store.delete(key);
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
return entry.value;
|
|
14
|
+
}
|
|
15
|
+
set(key, value) {
|
|
16
|
+
this.store.set(key, { key, value, createdAt: Date.now() });
|
|
17
|
+
}
|
|
18
|
+
makeKey(intent, prompt) {
|
|
19
|
+
const compact = prompt.trim().toLowerCase().replace(/\s+/g, " ");
|
|
20
|
+
return `${intent}:${compact.slice(0, 400)}`;
|
|
21
|
+
}
|
|
22
|
+
async loadFromFile(filePath) {
|
|
23
|
+
try {
|
|
24
|
+
const raw = await readFile(filePath, "utf8");
|
|
25
|
+
const parsed = JSON.parse(raw);
|
|
26
|
+
if (parsed.version !== 1)
|
|
27
|
+
return;
|
|
28
|
+
this.store.clear();
|
|
29
|
+
for (const entry of parsed.entries) {
|
|
30
|
+
this.store.set(entry.key, entry);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
// no cache yet
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
async saveToFile(filePath) {
|
|
38
|
+
await mkdir(path.dirname(filePath), { recursive: true });
|
|
39
|
+
const entries = Array.from(this.store.values());
|
|
40
|
+
const body = {
|
|
41
|
+
version: 1,
|
|
42
|
+
entries
|
|
43
|
+
};
|
|
44
|
+
await writeFile(filePath, `${JSON.stringify(body, null, 2)}\n`, "utf8");
|
|
45
|
+
}
|
|
46
|
+
clear() {
|
|
47
|
+
this.store.clear();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=semantic-cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"semantic-cache.js","sourceRoot":"","sources":["../../src/cache/semantic-cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,IAAI,MAAM,WAAW,CAAC;AAa7B,MAAM,OAAO,aAAa;IACP,KAAK,GAAG,IAAI,GAAG,EAA+B,CAAC;IAEhE,GAAG,CAAI,GAAW,EAAE,KAAc;QAChC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAClC,IAAI,CAAC,KAAK;YAAE,OAAO,SAAS,CAAC;QAC7B,IAAI,KAAK,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,SAAS,GAAG,KAAK,EAAE,CAAC;YAClD,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACvB,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,OAAO,KAAK,CAAC,KAAU,CAAC;IAC1B,CAAC;IAED,GAAG,CAAI,GAAW,EAAE,KAAQ;QAC1B,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;IAC7D,CAAC;IAED,OAAO,CAAC,MAAc,EAAE,MAAc;QACpC,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,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|
|
|
1
|
+
import { Policy } from "../../plugins/governance-plugin.js";
|
|
2
|
+
import { AgentInput, AgentOutput, PolicyDecision } from "../../types/contracts.js";
|
|
3
|
+
interface PIIPolicyConfig {
|
|
4
|
+
patterns?: Record<string, RegExp>;
|
|
5
|
+
detectors?: Record<string, boolean>;
|
|
6
|
+
}
|
|
7
|
+
interface DetectedPII {
|
|
8
|
+
type: string;
|
|
9
|
+
value: string;
|
|
10
|
+
position: number;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* PIIPolicy scans inputs and outputs for sensitive information like emails,
|
|
14
|
+
* phone numbers, and API keys using regex patterns.
|
|
15
|
+
*/
|
|
16
|
+
export declare class PIIPolicy implements Policy {
|
|
17
|
+
name: string;
|
|
18
|
+
private config;
|
|
19
|
+
private auditLogs;
|
|
20
|
+
private patterns;
|
|
21
|
+
constructor(config?: PIIPolicyConfig);
|
|
22
|
+
scan(text: string): DetectedPII[];
|
|
23
|
+
redact(text: string): string;
|
|
24
|
+
redactJSON(obj: any): any;
|
|
25
|
+
mask(text: string, type: string): string;
|
|
26
|
+
scanStructured(data: any): DetectedPII[];
|
|
27
|
+
scanArray(data: string[]): DetectedPII[];
|
|
28
|
+
generateReport(): {
|
|
29
|
+
totalDetected: number;
|
|
30
|
+
categories: Record<string, number>;
|
|
31
|
+
};
|
|
32
|
+
getAuditLogs(): string[];
|
|
33
|
+
validateInput(input: AgentInput): Promise<PolicyDecision>;
|
|
34
|
+
validateOutput(output: AgentOutput): Promise<PolicyDecision>;
|
|
35
|
+
}
|
|
36
|
+
export {};
|
|
37
|
+
//# sourceMappingURL=pii-policy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pii-policy.d.ts","sourceRoot":"","sources":["../../../src/governance/policies/pii-policy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,oCAAoC,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,cAAc,EAAmB,MAAM,0BAA0B,CAAC;AAEpG,UAAU,eAAe;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACvC;AAED,UAAU,WAAW;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;CACpB;AAED;;;GAGG;AACH,qBAAa,SAAU,YAAW,MAAM;IAC7B,IAAI,SAAoB;IAE/B,OAAO,CAAC,MAAM,CAAkB;IAChC,OAAO,CAAC,SAAS,CAAgB;IAEjC,OAAO,CAAC,QAAQ,CAOd;gBAEU,MAAM,GAAE,eAAoB;IAOxC,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,EAAE;IAqBjC,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAgB5B,UAAU,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG;IAoBzB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM;IAcxC,cAAc,CAAC,IAAI,EAAE,GAAG,GAAG,WAAW,EAAE;IAoBxC,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,WAAW,EAAE;IASxC,cAAc;;;;IAgBd,YAAY,IAAI,MAAM,EAAE;IAIlB,aAAa,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,cAAc,CAAC;IAiCzD,cAAc,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,cAAc,CAAC;CAmBrE"}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PIIPolicy scans inputs and outputs for sensitive information like emails,
|
|
3
|
+
* phone numbers, and API keys using regex patterns.
|
|
4
|
+
*/
|
|
5
|
+
export class PIIPolicy {
|
|
6
|
+
name = "PII_Protection";
|
|
7
|
+
config;
|
|
8
|
+
auditLogs = [];
|
|
9
|
+
patterns = {
|
|
10
|
+
email: /[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g,
|
|
11
|
+
apiKey: /(?:sk-(?:proj-)?|key-|auth-|ghp_|glpat-)[a-zA-Z0-9]{16,}/gi,
|
|
12
|
+
phone: /\+?\d{10,15}|(\d{3}[-.]?\d{3}[-.]?\d{4})/g,
|
|
13
|
+
ssn: /\d{3}-\d{2}-\d{4}/g,
|
|
14
|
+
credit_card: /\d{4}[-\s]?\d{4}[-\s]?\d{4}[-\s]?\d{4}/g,
|
|
15
|
+
ip_address: /\b(?:\d{1,3}\.){3}\d{1,3}\b/g
|
|
16
|
+
};
|
|
17
|
+
constructor(config = {}) {
|
|
18
|
+
this.config = config;
|
|
19
|
+
if (config.patterns) {
|
|
20
|
+
this.patterns = { ...this.patterns, ...config.patterns };
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
scan(text) {
|
|
24
|
+
const detected = [];
|
|
25
|
+
const detectors = this.config.detectors ?? { email: true, phone: true, ssn: true, credit_card: true, ip_address: true, apiKey: true };
|
|
26
|
+
for (const [type, pattern] of Object.entries(this.patterns)) {
|
|
27
|
+
if (detectors[type] === false)
|
|
28
|
+
continue;
|
|
29
|
+
pattern.lastIndex = 0;
|
|
30
|
+
let match;
|
|
31
|
+
while ((match = pattern.exec(text)) !== null) {
|
|
32
|
+
detected.push({
|
|
33
|
+
type,
|
|
34
|
+
value: match[0],
|
|
35
|
+
position: match.index
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return detected;
|
|
40
|
+
}
|
|
41
|
+
redact(text) {
|
|
42
|
+
const detected = this.scan(text);
|
|
43
|
+
let result = text;
|
|
44
|
+
// Sort by position in reverse to maintain correct positions when replacing
|
|
45
|
+
detected.sort((a, b) => b.position - a.position);
|
|
46
|
+
for (const pii of detected) {
|
|
47
|
+
const before = result.substring(0, pii.position);
|
|
48
|
+
const after = result.substring(pii.position + pii.value.length);
|
|
49
|
+
result = before + "[REDACTED]" + after;
|
|
50
|
+
}
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
redactJSON(obj) {
|
|
54
|
+
if (typeof obj !== "object" || obj === null)
|
|
55
|
+
return obj;
|
|
56
|
+
if (Array.isArray(obj)) {
|
|
57
|
+
return obj.map(item => this.redactJSON(item));
|
|
58
|
+
}
|
|
59
|
+
const result = {};
|
|
60
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
61
|
+
if (typeof value === "string") {
|
|
62
|
+
result[key] = this.redact(value);
|
|
63
|
+
}
|
|
64
|
+
else if (typeof value === "object" && value !== null) {
|
|
65
|
+
result[key] = this.redactJSON(value);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
result[key] = value;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
73
|
+
mask(text, type) {
|
|
74
|
+
if (type === "email") {
|
|
75
|
+
const [local, domain] = text.split("@");
|
|
76
|
+
return local.substring(0, 1) + "*".repeat(local.length - 2) + "@" + domain;
|
|
77
|
+
}
|
|
78
|
+
if (type === "phone") {
|
|
79
|
+
return "*".repeat(text.length - 4) + text.substring(text.length - 4);
|
|
80
|
+
}
|
|
81
|
+
if (type === "credit_card") {
|
|
82
|
+
return "*".repeat(text.length - 4) + text.substring(text.length - 4);
|
|
83
|
+
}
|
|
84
|
+
return text;
|
|
85
|
+
}
|
|
86
|
+
scanStructured(data) {
|
|
87
|
+
const detected = [];
|
|
88
|
+
const scan = (obj, path = "") => {
|
|
89
|
+
if (typeof obj === "string") {
|
|
90
|
+
const matches = this.scan(obj);
|
|
91
|
+
detected.push(...matches.map(m => ({ ...m, position: path.length + m.position })));
|
|
92
|
+
}
|
|
93
|
+
else if (typeof obj === "object" && obj !== null) {
|
|
94
|
+
if (Array.isArray(obj)) {
|
|
95
|
+
obj.forEach((item, idx) => scan(item, `${path}[${idx}]`));
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
99
|
+
scan(value, `${path}.${key}`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
scan(data);
|
|
105
|
+
return detected;
|
|
106
|
+
}
|
|
107
|
+
scanArray(data) {
|
|
108
|
+
const detected = [];
|
|
109
|
+
data.forEach((item, idx) => {
|
|
110
|
+
const matches = this.scan(item);
|
|
111
|
+
detected.push(...matches);
|
|
112
|
+
});
|
|
113
|
+
return detected;
|
|
114
|
+
}
|
|
115
|
+
generateReport() {
|
|
116
|
+
const categories = {};
|
|
117
|
+
let totalDetected = 0;
|
|
118
|
+
for (const log of this.auditLogs) {
|
|
119
|
+
const match = log.match(/type:(\w+)/);
|
|
120
|
+
if (match) {
|
|
121
|
+
const type = match[1];
|
|
122
|
+
categories[type] = (categories[type] ?? 0) + 1;
|
|
123
|
+
totalDetected++;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return { totalDetected, categories };
|
|
127
|
+
}
|
|
128
|
+
getAuditLogs() {
|
|
129
|
+
return [...this.auditLogs];
|
|
130
|
+
}
|
|
131
|
+
async validateInput(input) {
|
|
132
|
+
const violations = [];
|
|
133
|
+
const text = input.userPrompt;
|
|
134
|
+
// Reset regex patterns to avoid issues with global flag state
|
|
135
|
+
this.patterns.apiKey.lastIndex = 0;
|
|
136
|
+
this.patterns.email.lastIndex = 0;
|
|
137
|
+
this.patterns.phone.lastIndex = 0;
|
|
138
|
+
if (this.patterns.apiKey.test(text)) {
|
|
139
|
+
violations.push({
|
|
140
|
+
policy: this.name,
|
|
141
|
+
severity: "critical",
|
|
142
|
+
message: "Potential API Key or Secret detected in user prompt. Blocking for security."
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
// Email/Phone are often allowed but should be flagged in audit
|
|
146
|
+
this.patterns.email.lastIndex = 0;
|
|
147
|
+
if (this.patterns.email.test(text)) {
|
|
148
|
+
violations.push({
|
|
149
|
+
policy: this.name,
|
|
150
|
+
severity: "low",
|
|
151
|
+
message: "Email pattern detected."
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
return {
|
|
155
|
+
allowed: !violations.some(v => v.severity === "critical"),
|
|
156
|
+
violations
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
async validateOutput(output) {
|
|
160
|
+
const violations = [];
|
|
161
|
+
const text = JSON.stringify(output.data);
|
|
162
|
+
// Reset regex patterns to avoid issues with global flag state
|
|
163
|
+
this.patterns.apiKey.lastIndex = 0;
|
|
164
|
+
if (this.patterns.apiKey.test(text)) {
|
|
165
|
+
violations.push({
|
|
166
|
+
policy: this.name,
|
|
167
|
+
severity: "critical",
|
|
168
|
+
message: "Agent attempted to leak a sensitive API key in its response."
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
return {
|
|
172
|
+
allowed: !violations.some(v => v.severity === "critical"),
|
|
173
|
+
violations
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
//# sourceMappingURL=pii-policy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pii-policy.js","sourceRoot":"","sources":["../../../src/governance/policies/pii-policy.ts"],"names":[],"mappings":"AAcA;;;GAGG;AACH,MAAM,OAAO,SAAS;IACX,IAAI,GAAG,gBAAgB,CAAC;IAEvB,MAAM,CAAkB;IACxB,SAAS,GAAa,EAAE,CAAC;IAEzB,QAAQ,GAAG;QACf,KAAK,EAAE,iDAAiD;QACxD,MAAM,EAAE,4DAA4D;QACpE,KAAK,EAAE,2CAA2C;QAClD,GAAG,EAAE,oBAAoB;QACzB,WAAW,EAAE,yCAAyC;QACtD,UAAU,EAAE,8BAA8B;KAC7C,CAAC;IAEF,YAAY,SAA0B,EAAE;QACpC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;YAClB,I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,QAAQ,KAAK,UAAU,CAAC;YACzD,UAAU;SACb,CAAC;IACN,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,MAAmB;QACpC,MAAM,UAAU,GAAsB,EAAE,CAAC;QACzC,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAEzC,8DAA8D;QAC9D,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,SAAS,GAAG,CAAC,CAAC;QACnC,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YAClC,UAAU,CAAC,IAAI,CAAC;gBACZ,MAAM,EAAE,IAAI,CAAC,IAAI;gBACjB,QAAQ,EAAE,UAAU;gBACpB,OAAO,EAAE,8DAA8D;aAC1E,CAAC,CAAC;QACP,CAAC;QAED,OAAO;YACH,OAAO,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,UAAU,CAAC;YACzD,UAAU;SACb,CAAC;IACN,CAAC;CACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflow-graph.d.ts","sourceRoot":"","sources":["../../src/graph/workflow-graph.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAEpE,qBAAa,mBAAmB;IAC9B,iBAAiB,CAAC,KAAK,EAAE,aAAa,GAAG,YAAY,EAAE,EAAE;CAqC1D"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export class WorkflowGraphEngine {
|
|
2
|
+
topologicalLevels(graph) {
|
|
3
|
+
const nodes = new Map(graph.nodes.map((n) => [n.id, n]));
|
|
4
|
+
const indegree = new Map();
|
|
5
|
+
const reverse = new Map();
|
|
6
|
+
graph.nodes.forEach((n) => {
|
|
7
|
+
indegree.set(n.id, n.dependsOn.length);
|
|
8
|
+
n.dependsOn.forEach((dep) => {
|
|
9
|
+
if (!reverse.has(dep))
|
|
10
|
+
reverse.set(dep, []);
|
|
11
|
+
reverse.get(dep)?.push(n.id);
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
const levels = [];
|
|
15
|
+
let frontier = graph.nodes.filter((n) => (indegree.get(n.id) ?? 0) === 0);
|
|
16
|
+
while (frontier.length > 0) {
|
|
17
|
+
levels.push(frontier);
|
|
18
|
+
const next = [];
|
|
19
|
+
for (const node of frontier) {
|
|
20
|
+
for (const childId of reverse.get(node.id) ?? []) {
|
|
21
|
+
indegree.set(childId, (indegree.get(childId) ?? 1) - 1);
|
|
22
|
+
if ((indegree.get(childId) ?? 0) === 0) {
|
|
23
|
+
const child = nodes.get(childId);
|
|
24
|
+
if (child)
|
|
25
|
+
next.push(child);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
frontier = next;
|
|
30
|
+
}
|
|
31
|
+
const flattened = levels.flat().length;
|
|
32
|
+
if (flattened !== graph.nodes.length) {
|
|
33
|
+
throw new Error("workflow_cycle_or_missing_dependency");
|
|
34
|
+
}
|
|
35
|
+
return levels;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=workflow-graph.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflow-graph.js","sourceRoot":"","sources":["../../src/graph/workflow-graph.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,mBAAmB;IAC9B,iBAAiB,CAAC,KAAoB;QACpC,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;QACzD,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAkB,CAAC;QAC3C,MAAM,OAAO,GAAG,IAAI,GAAG,EAAoB,CAAC;QAE5C,KA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;wBACvC,MAAM,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;wBACjC,IAAI,KAAK;4BAAE,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;oBAC9B,CAAC;gBACH,CAAC;YACH,CAAC;YACD,QAAQ,GAAG,IAAI,CAAC;QAClB,CAAC;QAED,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC,MAAM,CAAC;QACvC,IAAI,SAAS,KAAK,KAAK,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;YACrC,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;QAC1D,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export * from "./types/contracts.js";
|
|
2
|
+
export * from "./orchestrator/core-orchestrator.js";
|
|
3
|
+
export * from "./orchestrator/routing.js";
|
|
4
|
+
export * from "./orchestrator/decomposition.js";
|
|
5
|
+
export * from "./orchestrator/default-workflow.js";
|
|
6
|
+
export * from "./orchestrator/verify-fix.js";
|
|
7
|
+
export * from "./orchestrator/kernel-bridge.js";
|
|
8
|
+
export * from "./orchestrator/blueprint-committer.js";
|
|
9
|
+
export * from "./orchestrator/dynamic-planner.js";
|
|
10
|
+
export * from "./orchestrator/mutation-applier.js";
|
|
11
|
+
export * from "./validator/structured-output-validator.js";
|
|
12
|
+
export * from "./recovery/error-recovery.js";
|
|
13
|
+
export * from "./cache/semantic-cache.js";
|
|
14
|
+
export * from "./metrics/metrics-engine.js";
|
|
15
|
+
export * from "./plugins/plugin-system.js";
|
|
16
|
+
export * from "./graph/workflow-graph.js";
|
|
17
|
+
export * from "./runtime/concurrency-scheduler.js";
|
|
18
|
+
export * from "./runtime/runtime-events.js";
|
|
19
|
+
export * from "./memory/local-vector-store.js";
|
|
20
|
+
export * from "./memory/graph-memory.js";
|
|
21
|
+
export * from "./memory/memory-manager.js";
|
|
22
|
+
export * from "./plugins/long-term-memory-plugin.js";
|
|
23
|
+
export * from "./plugins/governance-plugin.js";
|
|
24
|
+
export * from "./governance/policies/pii-policy.js";
|
|
25
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,qCAAqC,CAAC;AACpD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iCAAiC,CAAC;AAChD,cAAc,oCAAoC,CAAC;AACnD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,iCAAiC,CAAC;AAChD,cAAc,uCAAuC,CAAC;AACtD,cAAc,mCAAmC,CAAC;AAClD,cAAc,oCAAoC,CAAC;AACnD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,8BAA8B,CAAC;AAC7C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oCAAoC,CAAC;AACnD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,0BAA0B,CAAC;AACzC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sCAAsC,CAAC;AAErD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,qCAAqC,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export * from "./types/contracts.js";
|
|
2
|
+
export * from "./orchestrator/core-orchestrator.js";
|
|
3
|
+
export * from "./orchestrator/routing.js";
|
|
4
|
+
export * from "./orchestrator/decomposition.js";
|
|
5
|
+
export * from "./orchestrator/default-workflow.js";
|
|
6
|
+
export * from "./orchestrator/verify-fix.js";
|
|
7
|
+
export * from "./orchestrator/kernel-bridge.js";
|
|
8
|
+
export * from "./orchestrator/blueprint-committer.js";
|
|
9
|
+
export * from "./orchestrator/dynamic-planner.js";
|
|
10
|
+
export * from "./orchestrator/mutation-applier.js";
|
|
11
|
+
export * from "./validator/structured-output-validator.js";
|
|
12
|
+
export * from "./recovery/error-recovery.js";
|
|
13
|
+
export * from "./cache/semantic-cache.js";
|
|
14
|
+
export * from "./metrics/metrics-engine.js";
|
|
15
|
+
export * from "./plugins/plugin-system.js";
|
|
16
|
+
export * from "./graph/workflow-graph.js";
|
|
17
|
+
export * from "./runtime/concurrency-scheduler.js";
|
|
18
|
+
export * from "./runtime/runtime-events.js";
|
|
19
|
+
export * from "./memory/local-vector-store.js";
|
|
20
|
+
export * from "./memory/graph-memory.js";
|
|
21
|
+
export * from "./memory/memory-manager.js";
|
|
22
|
+
export * from "./plugins/long-term-memory-plugin.js";
|
|
23
|
+
export * from "./plugins/governance-plugin.js";
|
|
24
|
+
export * from "./governance/policies/pii-policy.js";
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,qCAAqC,CAAC;AACpD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iCAAiC,CAAC;AAChD,cAAc,oCAAoC,CAAC;AACnD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,iCAAiC,CAAC;AAChD,cAAc,uCAAuC,CAAC;AACtD,cAAc,mCAAmC,CAAC;AAClD,cAAc,oCAAoC,CAAC;AACnD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,8BAA8B,CAAC;AAC7C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oCAAoC,CAAC;AACnD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,0BAA0B,CAAC;AACzC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sCAAsC,CAAC;AAErD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,qCAAqC,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export interface GraphNode {
|
|
2
|
+
id: string;
|
|
3
|
+
type: "action" | "artifact" | "concept" | "agent";
|
|
4
|
+
content: string;
|
|
5
|
+
metadata: Record<string, any>;
|
|
6
|
+
timestamp: number;
|
|
7
|
+
}
|
|
8
|
+
export interface GraphEdge {
|
|
9
|
+
from: string;
|
|
10
|
+
to: string;
|
|
11
|
+
type: "produced" | "triggered_by" | "depends_on" | "relates_to";
|
|
12
|
+
metadata?: Record<string, any>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Quantum Semantic Graph Memory (QSGM) Core.
|
|
16
|
+
* Manages relationships between actions, artifacts, and concepts.
|
|
17
|
+
*/
|
|
18
|
+
export declare class GraphMemory {
|
|
19
|
+
private persistPath?;
|
|
20
|
+
private nodes;
|
|
21
|
+
private edges;
|
|
22
|
+
constructor(persistPath?: string | undefined);
|
|
23
|
+
addNode(node: GraphNode): void;
|
|
24
|
+
removeNode(nodeId: string): boolean;
|
|
25
|
+
addEdge(edge: GraphEdge): void;
|
|
26
|
+
/**
|
|
27
|
+
* Traverses the graph to find nodes related to a starting point.
|
|
28
|
+
* Useful for finding "ripple effects" or deep context.
|
|
29
|
+
*/
|
|
30
|
+
traverse(startNodeId: string, maxDepth?: number): GraphNode[];
|
|
31
|
+
load(): Promise<void>;
|
|
32
|
+
save(): Promise<void>;
|
|
33
|
+
getNodes(): GraphNode[];
|
|
34
|
+
getGraphData(): {
|
|
35
|
+
nodes: Record<string, GraphNode>;
|
|
36
|
+
edges: GraphEdge[];
|
|
37
|
+
};
|
|
38
|
+
findByType(type: string): GraphNode[];
|
|
39
|
+
search(query: string, limit?: number): GraphNode[];
|
|
40
|
+
getConnections(nodeId: string): {
|
|
41
|
+
incoming: GraphNode[];
|
|
42
|
+
outgoing: GraphNode[];
|
|
43
|
+
};
|
|
44
|
+
getStats(): any;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=graph-memory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph-memory.d.ts","sourceRoot":"","sources":["../../src/memory/graph-memory.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,SAAS;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,QAAQ,GAAG,UAAU,GAAG,SAAS,GAAG,OAAO,CAAC;IAClD,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC9B,SAAS,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,SAAS;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,UAAU,GAAG,cAAc,GAAG,YAAY,GAAG,YAAY,CAAC;IAChE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAClC;AAED;;;GAGG;AACH,qBAAa,WAAW;IAIR,OAAO,CAAC,WAAW,CAAC;IAHhC,OAAO,CAAC,KAAK,CAAqC;IAClD,OAAO,CAAC,KAAK,CAAmB;gBAEZ,WAAW,CAAC,EAAE,MAAM,YAAA;IAEjC,OAAO,CAAC,IAAI,EAAE,SAAS,GAAG,IAAI;IAI9B,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAOnC,OAAO,CAAC,IAAI,EAAE,SAAS,GAAG,IAAI;IAIrC;;;OAGG;IACI,QAAQ,CAAC,WAAW,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAU,GAAG,SAAS,EAAE;IA8B1D,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAarB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAa3B,QAAQ,IAAI,SAAS,EAAE;IAIvB,YAAY,IAAI;QAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;QAAC,KAAK,EAAE,SAAS,EAAE,CAAA;KAAE;IAOxE,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,EAAE;IAIrC,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,GAAE,MAAU,GAAG,SAAS,EAAE;IAMrD,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG;QAAE,QAAQ,EAAE,SAAS,EAAE,CAAC;QAAC,QAAQ,EAAE,SAAS,EAAE,CAAA;KAAE;IAchF,QAAQ,IAAI,GAAG;CAUzB"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { readFile, writeFile, mkdir } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
/**
|
|
4
|
+
* Quantum Semantic Graph Memory (QSGM) Core.
|
|
5
|
+
* Manages relationships between actions, artifacts, and concepts.
|
|
6
|
+
*/
|
|
7
|
+
export class GraphMemory {
|
|
8
|
+
persistPath;
|
|
9
|
+
nodes = new Map();
|
|
10
|
+
edges = [];
|
|
11
|
+
constructor(persistPath) {
|
|
12
|
+
this.persistPath = persistPath;
|
|
13
|
+
}
|
|
14
|
+
addNode(node) {
|
|
15
|
+
this.nodes.set(node.id, node);
|
|
16
|
+
}
|
|
17
|
+
removeNode(nodeId) {
|
|
18
|
+
if (!this.nodes.has(nodeId))
|
|
19
|
+
return false;
|
|
20
|
+
this.nodes.delete(nodeId);
|
|
21
|
+
this.edges = this.edges.filter(e => e.from !== nodeId && e.to !== nodeId);
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
addEdge(edge) {
|
|
25
|
+
this.edges.push(edge);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Traverses the graph to find nodes related to a starting point.
|
|
29
|
+
* Useful for finding "ripple effects" or deep context.
|
|
30
|
+
*/
|
|
31
|
+
traverse(startNodeId, maxDepth = 2) {
|
|
32
|
+
const visited = new Set();
|
|
33
|
+
const results = [];
|
|
34
|
+
const queue = [{ id: startNodeId, depth: 0 }];
|
|
35
|
+
while (queue.length > 0) {
|
|
36
|
+
const { id, depth } = queue.shift();
|
|
37
|
+
if (visited.has(id) || depth > maxDepth)
|
|
38
|
+
continue;
|
|
39
|
+
visited.add(id);
|
|
40
|
+
const node = this.nodes.get(id);
|
|
41
|
+
if (node) {
|
|
42
|
+
results.push(node);
|
|
43
|
+
}
|
|
44
|
+
// Find neighbors
|
|
45
|
+
const neighbors = this.edges
|
|
46
|
+
.filter(e => e.from === id)
|
|
47
|
+
.map(e => ({ id: e.to, depth: depth + 1 }));
|
|
48
|
+
const reverseNeighbors = this.edges
|
|
49
|
+
.filter(e => e.to === id)
|
|
50
|
+
.map(e => ({ id: e.from, depth: depth + 1 }));
|
|
51
|
+
queue.push(...neighbors, ...reverseNeighbors);
|
|
52
|
+
}
|
|
53
|
+
return results;
|
|
54
|
+
}
|
|
55
|
+
async load() {
|
|
56
|
+
if (!this.persistPath)
|
|
57
|
+
return;
|
|
58
|
+
try {
|
|
59
|
+
const raw = await readFile(this.persistPath, "utf8");
|
|
60
|
+
const data = JSON.parse(raw);
|
|
61
|
+
this.nodes = new Map(Object.entries(data.nodes || {}));
|
|
62
|
+
this.edges = data.edges || [];
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
this.nodes = new Map();
|
|
66
|
+
this.edges = [];
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
async save() {
|
|
70
|
+
if (!this.persistPath)
|
|
71
|
+
return;
|
|
72
|
+
try {
|
|
73
|
+
await mkdir(path.dirname(this.persistPath), { recursive: true });
|
|
74
|
+
await writeFile(this.persistPath, JSON.stringify({
|
|
75
|
+
nodes: Object.fromEntries(this.nodes),
|
|
76
|
+
edges: this.edges
|
|
77
|
+
}, null, 2));
|
|
78
|
+
}
|
|
79
|
+
catch (err) {
|
|
80
|
+
console.error("Failed to persist graph memory:", err);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
getNodes() {
|
|
84
|
+
return Array.from(this.nodes.values());
|
|
85
|
+
}
|
|
86
|
+
getGraphData() {
|
|
87
|
+
return {
|
|
88
|
+
nodes: Object.fromEntries(this.nodes),
|
|
89
|
+
edges: this.edges
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
findByType(type) {
|
|
93
|
+
return Array.from(this.nodes.values()).filter(n => n.type === type);
|
|
94
|
+
}
|
|
95
|
+
search(query, limit = 5) {
|
|
96
|
+
return Array.from(this.nodes.values())
|
|
97
|
+
.filter(n => n.content?.includes(query) || JSON.stringify(n.metadata).includes(query))
|
|
98
|
+
.slice(0, limit);
|
|
99
|
+
}
|
|
100
|
+
getConnections(nodeId) {
|
|
101
|
+
const incoming = this.edges
|
|
102
|
+
.filter(e => e.to === nodeId)
|
|
103
|
+
.map(e => this.nodes.get(e.from))
|
|
104
|
+
.filter(Boolean);
|
|
105
|
+
const outgoing = this.edges
|
|
106
|
+
.filter(e => e.from === nodeId)
|
|
107
|
+
.map(e => this.nodes.get(e.to))
|
|
108
|
+
.filter(Boolean);
|
|
109
|
+
return { incoming, outgoing };
|
|
110
|
+
}
|
|
111
|
+
getStats() {
|
|
112
|
+
return {
|
|
113
|
+
nodeCount: this.nodes.size,
|
|
114
|
+
edgeCount: this.edges.length,
|
|
115
|
+
nodesByType: Array.from(this.nodes.values()).reduce((acc, n) => {
|
|
116
|
+
acc[n.type] = (acc[n.type] || 0) + 1;
|
|
117
|
+
return acc;
|
|
118
|
+
}, {})
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=graph-memory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph-memory.js","sourceRoot":"","sources":["../../src/memory/graph-memory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,IAAI,M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CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,GAA2B,EAAE,CAAC,EAAE,EAAE;gBACnF,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;gBACrC,OAAO,GAAG,CAAC;YACf,CAAC,EAAE,EAAE,CAAC;SACT,CAAC;IACN,CAAC;CACJ"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { IVectorStore, MemoryDocument, SearchResult } from "../types/contracts.js";
|
|
2
|
+
/**
|
|
3
|
+
* A lightweight, local vector store using Cosine Similarity.
|
|
4
|
+
* Suitable for small-to-medium datasets (thousands of records).
|
|
5
|
+
* Persists data to a simple JSON structure.
|
|
6
|
+
*/
|
|
7
|
+
export declare class LocalVectorStore implements IVectorStore {
|
|
8
|
+
private persistPath?;
|
|
9
|
+
private documents;
|
|
10
|
+
private vectors;
|
|
11
|
+
private metadata;
|
|
12
|
+
constructor(persistPath?: string | undefined);
|
|
13
|
+
add(documents: MemoryDocument[], vectors: number[][]): Promise<void>;
|
|
14
|
+
search(queryVector: number[], limit?: number): Promise<SearchResult[]>;
|
|
15
|
+
clear(): Promise<void>;
|
|
16
|
+
delete(docIds: string[]): Promise<void>;
|
|
17
|
+
searchByMetadata(metadata: Record<string, unknown>): Promise<SearchResult[]>;
|
|
18
|
+
count(): number;
|
|
19
|
+
getMetrics(): {
|
|
20
|
+
documentCount: number;
|
|
21
|
+
vectorDimensions: number;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Calculates cosine similarity between two numeric vectors.
|
|
25
|
+
*/
|
|
26
|
+
private cosineSimilarity;
|
|
27
|
+
/**
|
|
28
|
+
* Manually triggers a load from the persistence file.
|
|
29
|
+
*/
|
|
30
|
+
load(): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Internal save to disk.
|
|
33
|
+
*/
|
|
34
|
+
private save;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=local-vector-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-vector-store.d.ts","sourceRoot":"","sources":["../../src/memory/local-vector-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAInF;;;;GAIG;AACH,qBAAa,gBAAiB,YAAW,YAAY;IAKrC,OAAO,CAAC,WAAW,CAAC;IAJhC,OAAO,CAAC,SAAS,CAAwB;IACzC,OAAO,CAAC,OAAO,CAAkB;IACjC,OAAO,CAAC,QAAQ,CAAmD;gBAE/C,WAAW,CAAC,EAAE,MAAM,YAAA;IAElC,GAAG,CAAC,SAAS,EAAE,cAAc,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IASpE,MAAM,CAAC,WAAW,EAAE,MAAM,EAAE,EAAE,KAAK,GAAE,MAAU,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;IAazE,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAOtB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAYvC,gBAAgB,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;IAO3E,KAAK,IAAI,MAAM;IAIf,UAAU;;;;IAOjB;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAkBxB;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAc3B;;OAEG;YACW,IAAI;CAYrB"}
|