@miller-tech/uap 1.5.4 → 1.5.6
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/.tsbuildinfo +1 -0
- package/dist/bin/cli.js +6 -0
- package/dist/bin/cli.js.map +1 -1
- package/dist/bin/llama-server-optimize.js +0 -0
- package/dist/bin/policy.js +0 -0
- package/dist/bin/tool-calls.js +0 -0
- package/dist/cli/dashboard.d.ts +1 -0
- package/dist/cli/dashboard.d.ts.map +1 -1
- package/dist/cli/dashboard.js.map +1 -1
- package/dist/memory/active-context.d.ts +65 -0
- package/dist/memory/active-context.d.ts.map +1 -0
- package/dist/memory/active-context.js +126 -0
- package/dist/memory/active-context.js.map +1 -0
- package/dist/memory/dedup-detector.d.ts +57 -0
- package/dist/memory/dedup-detector.d.ts.map +1 -0
- package/dist/memory/dedup-detector.js +107 -0
- package/dist/memory/dedup-detector.js.map +1 -0
- package/dist/memory/dedup-memory.d.ts +89 -0
- package/dist/memory/dedup-memory.d.ts.map +1 -0
- package/dist/memory/dedup-memory.js +173 -0
- package/dist/memory/dedup-memory.js.map +1 -0
- package/dist/memory/merge-claude-md.d.ts +45 -0
- package/dist/memory/merge-claude-md.d.ts.map +1 -0
- package/dist/memory/merge-claude-md.js +118 -0
- package/dist/memory/merge-claude-md.js.map +1 -0
- package/dist/memory/patterns.d.ts +37 -0
- package/dist/memory/patterns.d.ts.map +1 -0
- package/dist/memory/patterns.js +81 -0
- package/dist/memory/patterns.js.map +1 -0
- package/dist/memory/semantic-edge-graph.d.ts +86 -0
- package/dist/memory/semantic-edge-graph.d.ts.map +1 -0
- package/dist/memory/semantic-edge-graph.js +168 -0
- package/dist/memory/semantic-edge-graph.js.map +1 -0
- package/dist/memory/semantic-retrieval.d.ts +70 -0
- package/dist/memory/semantic-retrieval.d.ts.map +1 -0
- package/dist/memory/semantic-retrieval.js +112 -0
- package/dist/memory/semantic-retrieval.js.map +1 -0
- package/dist/memory/smart-consolidator.d.ts +53 -0
- package/dist/memory/smart-consolidator.d.ts.map +1 -0
- package/dist/memory/smart-consolidator.js +144 -0
- package/dist/memory/smart-consolidator.js.map +1 -0
- package/dist/memory/view-memory.d.ts +80 -0
- package/dist/memory/view-memory.d.ts.map +1 -0
- package/dist/memory/view-memory.js +130 -0
- package/dist/memory/view-memory.js.map +1 -0
- package/dist/memory/wrapped-memory.d.ts +77 -0
- package/dist/memory/wrapped-memory.d.ts.map +1 -0
- package/dist/memory/wrapped-memory.js +127 -0
- package/dist/memory/wrapped-memory.js.map +1 -0
- package/dist/telemetry/session-telemetry.d.ts +5 -0
- package/dist/telemetry/session-telemetry.d.ts.map +1 -1
- package/dist/telemetry/session-telemetry.js +243 -0
- package/dist/telemetry/session-telemetry.js.map +1 -1
- package/dist/utils/adaptive-cache.d.ts +67 -0
- package/dist/utils/adaptive-cache.d.ts.map +1 -0
- package/dist/utils/adaptive-cache.js +149 -0
- package/dist/utils/adaptive-cache.js.map +1 -0
- package/dist/utils/concurrency.d.ts +33 -0
- package/dist/utils/concurrency.d.ts.map +1 -0
- package/dist/utils/concurrency.js +88 -0
- package/dist/utils/concurrency.js.map +1 -0
- package/dist/utils/file-discovery.d.ts +38 -0
- package/dist/utils/file-discovery.d.ts.map +1 -0
- package/dist/utils/file-discovery.js +100 -0
- package/dist/utils/file-discovery.js.map +1 -0
- package/dist/utils/performance-monitor.d.ts +52 -0
- package/dist/utils/performance-monitor.d.ts.map +1 -0
- package/dist/utils/performance-monitor.js +103 -0
- package/dist/utils/performance-monitor.js.map +1 -0
- package/package.json +5 -3
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Merge Claude MD Module for UAP
|
|
3
|
+
*
|
|
4
|
+
* Provides utilities for merging multiple Claude.md knowledge files
|
|
5
|
+
* into a single consolidated document.
|
|
6
|
+
*/
|
|
7
|
+
export interface ClaudeMD {
|
|
8
|
+
title: string;
|
|
9
|
+
content: string;
|
|
10
|
+
sections: Section[];
|
|
11
|
+
metadata: Record<string, any>;
|
|
12
|
+
}
|
|
13
|
+
export interface Section {
|
|
14
|
+
heading: string;
|
|
15
|
+
level: number;
|
|
16
|
+
content: string;
|
|
17
|
+
children: Section[];
|
|
18
|
+
}
|
|
19
|
+
export interface MergeConfig {
|
|
20
|
+
deduplicate: boolean;
|
|
21
|
+
dedupThreshold: number;
|
|
22
|
+
prioritySections: string[];
|
|
23
|
+
maxSectionLength: number;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Merge multiple Claude.md files into one
|
|
27
|
+
*/
|
|
28
|
+
export declare function mergeClaudeMDs(files: Array<{
|
|
29
|
+
name: string;
|
|
30
|
+
content: string;
|
|
31
|
+
}>, config?: Partial<MergeConfig>): {
|
|
32
|
+
merged: string;
|
|
33
|
+
sections: Section[];
|
|
34
|
+
stats: MergeStats;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Merge stats interface
|
|
38
|
+
*/
|
|
39
|
+
export interface MergeStats {
|
|
40
|
+
filesProcessed: number;
|
|
41
|
+
totalSections: number;
|
|
42
|
+
duplicatesRemoved: number;
|
|
43
|
+
finalLength: number;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=merge-claude-md.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge-claude-md.d.ts","sourceRoot":"","sources":["../../src/memory/merge-claude-md.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,WAAW,QAAQ;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC/B;AAED,MAAM,WAAW,OAAO;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,OAAO,EAAE,CAAC;CACrB;AAED,MAAM,WAAW,WAAW;IAC1B,WAAW,EAAE,OAAO,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AASD;;GAEG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC,EAC/C,MAAM,GAAE,OAAO,CAAC,WAAW,CAAM,GAChC;IACD,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,KAAK,EAAE,UAAU,CAAC;CACnB,CAwDA;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;IACtB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,WAAW,EAAE,MAAM,CAAC;CACrB"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Merge Claude MD Module for UAP
|
|
3
|
+
*
|
|
4
|
+
* Provides utilities for merging multiple Claude.md knowledge files
|
|
5
|
+
* into a single consolidated document.
|
|
6
|
+
*/
|
|
7
|
+
const DEFAULT_CONFIG = {
|
|
8
|
+
deduplicate: true,
|
|
9
|
+
dedupThreshold: 0.85,
|
|
10
|
+
prioritySections: ['Architecture', 'Setup', 'Configuration', 'Known Issues'],
|
|
11
|
+
maxSectionLength: 10000,
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Merge multiple Claude.md files into one
|
|
15
|
+
*/
|
|
16
|
+
export function mergeClaudeMDs(files, config = {}) {
|
|
17
|
+
const cfg = { ...DEFAULT_CONFIG, ...config };
|
|
18
|
+
const stats = {
|
|
19
|
+
filesProcessed: files.length,
|
|
20
|
+
totalSections: 0,
|
|
21
|
+
duplicatesRemoved: 0,
|
|
22
|
+
finalLength: 0,
|
|
23
|
+
};
|
|
24
|
+
if (files.length === 0) {
|
|
25
|
+
return {
|
|
26
|
+
merged: '',
|
|
27
|
+
sections: [],
|
|
28
|
+
stats,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
// Parse all files
|
|
32
|
+
const parsedFiles = files.map((file) => ({
|
|
33
|
+
name: file.name,
|
|
34
|
+
sections: parseMarkdown(file.content),
|
|
35
|
+
}));
|
|
36
|
+
stats.totalSections = parsedFiles.reduce((sum, f) => sum + f.sections.length, 0);
|
|
37
|
+
// Merge sections with deduplication
|
|
38
|
+
const mergedSections = [];
|
|
39
|
+
const seenContents = new Set();
|
|
40
|
+
// Sort by priority
|
|
41
|
+
const sortedFiles = [...parsedFiles].sort((a, b) => {
|
|
42
|
+
const aPriority = countPrioritySections(a.sections, cfg.prioritySections);
|
|
43
|
+
const bPriority = countPrioritySections(b.sections, cfg.prioritySections);
|
|
44
|
+
return bPriority - aPriority;
|
|
45
|
+
});
|
|
46
|
+
for (const file of sortedFiles) {
|
|
47
|
+
for (const section of file.sections) {
|
|
48
|
+
if (!cfg.deduplicate || !seenContents.has(section.content)) {
|
|
49
|
+
mergedSections.push(section);
|
|
50
|
+
seenContents.add(section.content);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
stats.duplicatesRemoved++;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
// Build final document
|
|
58
|
+
const merged = buildDocument(mergedSections, files[0].name.replace('.md', ''));
|
|
59
|
+
stats.finalLength = merged.length;
|
|
60
|
+
return {
|
|
61
|
+
merged,
|
|
62
|
+
sections: mergedSections,
|
|
63
|
+
stats,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Parse markdown content into sections
|
|
68
|
+
*/
|
|
69
|
+
function parseMarkdown(content) {
|
|
70
|
+
const sections = [];
|
|
71
|
+
const lines = content.split('\n');
|
|
72
|
+
let currentSection = null;
|
|
73
|
+
for (const line of lines) {
|
|
74
|
+
const headingMatch = line.match(/^(#{1,6})\s+(.+)$/);
|
|
75
|
+
if (headingMatch) {
|
|
76
|
+
// Save previous section
|
|
77
|
+
if (currentSection) {
|
|
78
|
+
sections.push(currentSection);
|
|
79
|
+
}
|
|
80
|
+
// Start new section
|
|
81
|
+
currentSection = {
|
|
82
|
+
heading: headingMatch[2].trim(),
|
|
83
|
+
level: headingMatch[1].length,
|
|
84
|
+
content: '',
|
|
85
|
+
children: [],
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
else if (currentSection) {
|
|
89
|
+
// Accumulate section content
|
|
90
|
+
currentSection.content += line + '\n';
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
// Don't forget the last section
|
|
94
|
+
if (currentSection) {
|
|
95
|
+
sections.push(currentSection);
|
|
96
|
+
}
|
|
97
|
+
return sections;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Count priority sections in a file
|
|
101
|
+
*/
|
|
102
|
+
function countPrioritySections(sections, prioritySections) {
|
|
103
|
+
return sections.filter((s) => prioritySections.some((p) => s.heading.includes(p))).length;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Build markdown document from sections
|
|
107
|
+
*/
|
|
108
|
+
function buildDocument(sections, title) {
|
|
109
|
+
const lines = [`# ${title}\n`];
|
|
110
|
+
for (const section of sections) {
|
|
111
|
+
lines.push(`#${' '.repeat(section.level - 1)} ${section.heading}`);
|
|
112
|
+
lines.push('');
|
|
113
|
+
lines.push(section.content.trim());
|
|
114
|
+
lines.push('');
|
|
115
|
+
}
|
|
116
|
+
return lines.join('\n').trim();
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=merge-claude-md.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge-claude-md.js","sourceRoot":"","sources":["../../src/memory/merge-claude-md.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAuBH,MAAM,c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E,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACf,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;QACnC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACjB,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC;AACjC,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory Patterns Module for UAP
|
|
3
|
+
*
|
|
4
|
+
* Provides common memory patterns and utilities for agent memory management.
|
|
5
|
+
*/
|
|
6
|
+
export interface MemoryPattern {
|
|
7
|
+
id: string;
|
|
8
|
+
name: string;
|
|
9
|
+
description: string;
|
|
10
|
+
template: string;
|
|
11
|
+
variables: string[];
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Common memory patterns for agents
|
|
15
|
+
*/
|
|
16
|
+
export declare const MEMORY_PATTERNS: MemoryPattern[];
|
|
17
|
+
/**
|
|
18
|
+
* Fill in a pattern template with values
|
|
19
|
+
*/
|
|
20
|
+
export declare function fillPattern(pattern: MemoryPattern, values: Record<string, string>): string;
|
|
21
|
+
/**
|
|
22
|
+
* Get a pattern by ID
|
|
23
|
+
*/
|
|
24
|
+
export declare function getPattern(id: string): MemoryPattern | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Search patterns by keywords
|
|
27
|
+
*/
|
|
28
|
+
export declare function searchPatterns(query: string): MemoryPattern[];
|
|
29
|
+
/**
|
|
30
|
+
* Get all pattern IDs
|
|
31
|
+
*/
|
|
32
|
+
export declare function getPatternIds(): string[];
|
|
33
|
+
/**
|
|
34
|
+
* Create a new pattern
|
|
35
|
+
*/
|
|
36
|
+
export declare function createPattern(id: string, name: string, description: string, template: string, variables: string[]): MemoryPattern;
|
|
37
|
+
//# sourceMappingURL=patterns.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patterns.d.ts","sourceRoot":"","sources":["../../src/memory/patterns.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,EAAE,CAAC;CACrB;AAED;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,aAAa,EAyC1C,CAAC;AAEF;;GAEG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAQ1F;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,CAEhE;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,aAAa,EAAE,CAO7D;AAED;;GAEG;AACH,wBAAgB,aAAa,IAAI,MAAM,EAAE,CAExC;AAED;;GAEG;AACH,wBAAgB,aAAa,CAC3B,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EAAE,GAClB,aAAa,CAEf"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory Patterns Module for UAP
|
|
3
|
+
*
|
|
4
|
+
* Provides common memory patterns and utilities for agent memory management.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Common memory patterns for agents
|
|
8
|
+
*/
|
|
9
|
+
export const MEMORY_PATTERNS = [
|
|
10
|
+
{
|
|
11
|
+
id: 'decision',
|
|
12
|
+
name: 'Decision Log',
|
|
13
|
+
description: 'Record a decision made by the agent',
|
|
14
|
+
template: '# Decision: {{title}}\n\n**Context:** {{context}}\n\n**Decision:** {{decision}}\n\n**Reasoning:** {{reasoning}}\n\n**Expected Outcome:** {{outcome}}',
|
|
15
|
+
variables: ['title', 'context', 'decision', 'reasoning', 'outcome'],
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
id: 'lesson',
|
|
19
|
+
name: 'Lesson Learned',
|
|
20
|
+
description: 'Capture a lesson learned during development',
|
|
21
|
+
template: '# Lesson: {{title}}\n\n**Problem:** {{problem}}\n\n**Solution:** {{solution}}\n\n**Key Insight:** {{insight}}\n\n**When to Apply:** {{whenToApply}}',
|
|
22
|
+
variables: ['title', 'problem', 'solution', 'insight', 'whenToApply'],
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
id: 'gotcha',
|
|
26
|
+
name: 'Gotcha / Warning',
|
|
27
|
+
description: 'Document a common pitfall or gotcha',
|
|
28
|
+
template: '# ⚠️ Gotcha: {{title}}\n\n**What to Avoid:** {{avoid}}\n\n**Why:** {{why}}\n\n**Correct Approach:** {{correctApproach}}',
|
|
29
|
+
variables: ['title', 'avoid', 'why', 'correctApproach'],
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
id: 'pattern',
|
|
33
|
+
name: 'Design Pattern',
|
|
34
|
+
description: 'Document a recurring design pattern',
|
|
35
|
+
template: '# Pattern: {{title}}\n\n**Purpose:** {{purpose}}\n\n**Structure:** {{structure}}\n\n**Usage Example:**\n\n```{{language}}\n{{example}}\n```',
|
|
36
|
+
variables: ['title', 'purpose', 'structure', 'language', 'example'],
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
id: 'architecture',
|
|
40
|
+
name: 'Architecture Decision',
|
|
41
|
+
description: 'Record an architectural decision',
|
|
42
|
+
template: '# ADR: {{title}}\n\n**Status:** {{status}}\n\n**Context:** {{context}}\n\n**Decision:** {{decision}}\n\n**Consequences:** {{consequences}}',
|
|
43
|
+
variables: ['title', 'status', 'context', 'decision', 'consequences'],
|
|
44
|
+
},
|
|
45
|
+
];
|
|
46
|
+
/**
|
|
47
|
+
* Fill in a pattern template with values
|
|
48
|
+
*/
|
|
49
|
+
export function fillPattern(pattern, values) {
|
|
50
|
+
let result = pattern.template;
|
|
51
|
+
for (const [key, value] of Object.entries(values)) {
|
|
52
|
+
result = result.replace(new RegExp(`{{${key}}}`, 'g'), value);
|
|
53
|
+
}
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Get a pattern by ID
|
|
58
|
+
*/
|
|
59
|
+
export function getPattern(id) {
|
|
60
|
+
return MEMORY_PATTERNS.find((p) => p.id === id);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Search patterns by keywords
|
|
64
|
+
*/
|
|
65
|
+
export function searchPatterns(query) {
|
|
66
|
+
const lowerQuery = query.toLowerCase();
|
|
67
|
+
return MEMORY_PATTERNS.filter((p) => p.name.toLowerCase().includes(lowerQuery) || p.description.toLowerCase().includes(lowerQuery));
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Get all pattern IDs
|
|
71
|
+
*/
|
|
72
|
+
export function getPatternIds() {
|
|
73
|
+
return MEMORY_PATTERNS.map((p) => p.id);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Create a new pattern
|
|
77
|
+
*/
|
|
78
|
+
export function createPattern(id, name, description, template, variables) {
|
|
79
|
+
return { id, name, description, template, variables };
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=patterns.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patterns.js","sourceRoot":"","sources":["../../src/memory/patterns.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAUH;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAoB;IAC9C;QACE,EAAE,EAAE,UAAU;QACd,IAAI,EAAE,cAAc;QACpB,WAAW,EAAE,qCAAqC;QAClD,QAAQ,EACN,sJAAsJ;QACxJ,SAAS,EAAE,CAAC,OAAO,EAAE,SAAS,EAAE,UA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AEG;AACH,MAAM,UAAU,UAAU,CAAC,EAAU;IACnC,OAAO,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;AAClD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,KAAa;IAC1C,MAAM,UAAU,GAAG,KAAK,CAAC,WAAW,EAAE,CAAC;IAEvC,OAAO,eAAe,CAAC,MAAM,CAC3B,CAAC,CAAC,EAAE,EAAE,CACJ,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,WAAW,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,UAAU,CAAC,CAChG,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa;IAC3B,OAAO,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AAC1C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAC3B,EAAU,EACV,IAAY,EACZ,WAAmB,EACnB,QAAgB,EAChB,SAAmB;IAEnB,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC;AACxD,CAAC"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Semantic Edge Graph Module for UAP
|
|
3
|
+
*
|
|
4
|
+
* Implements a knowledge graph with semantic edges for efficient memory retrieval.
|
|
5
|
+
*/
|
|
6
|
+
export interface GraphNode {
|
|
7
|
+
id: string;
|
|
8
|
+
content: string;
|
|
9
|
+
type: 'concept' | 'fact' | 'entity' | 'relationship';
|
|
10
|
+
metadata: Record<string, any>;
|
|
11
|
+
embedding?: number[];
|
|
12
|
+
}
|
|
13
|
+
export interface GraphEdge {
|
|
14
|
+
source: string;
|
|
15
|
+
target: string;
|
|
16
|
+
type: string;
|
|
17
|
+
weight: number;
|
|
18
|
+
metadata: Record<string, any>;
|
|
19
|
+
}
|
|
20
|
+
export interface SemanticEdgeGraphConfig {
|
|
21
|
+
maxEdgesPerNode: number;
|
|
22
|
+
similarityThreshold: number;
|
|
23
|
+
decayRate: number;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Semantic Edge Graph
|
|
27
|
+
* A knowledge graph with semantic connections between nodes
|
|
28
|
+
*/
|
|
29
|
+
export declare class SemanticEdgeGraph {
|
|
30
|
+
private config;
|
|
31
|
+
private nodes;
|
|
32
|
+
private edges;
|
|
33
|
+
constructor(config?: Partial<SemanticEdgeGraphConfig>);
|
|
34
|
+
/**
|
|
35
|
+
* Add a node to the graph
|
|
36
|
+
*/
|
|
37
|
+
addNode(node: GraphNode): void;
|
|
38
|
+
/**
|
|
39
|
+
* Add an edge between nodes
|
|
40
|
+
*/
|
|
41
|
+
addEdge(source: string, target: string, type: string, weight?: number): void;
|
|
42
|
+
private addEdgeToAdjacency;
|
|
43
|
+
/**
|
|
44
|
+
* Get neighbors of a node
|
|
45
|
+
*/
|
|
46
|
+
getNeighbors(nodeId: string, limit?: number): Array<{
|
|
47
|
+
nodeId: string;
|
|
48
|
+
edge: GraphEdge;
|
|
49
|
+
}>;
|
|
50
|
+
/**
|
|
51
|
+
* Get all nodes
|
|
52
|
+
*/
|
|
53
|
+
getAllNodes(): GraphNode[];
|
|
54
|
+
/**
|
|
55
|
+
* Get a node by ID
|
|
56
|
+
*/
|
|
57
|
+
getNode(nodeId: string): GraphNode | null;
|
|
58
|
+
/**
|
|
59
|
+
* Find similar nodes by content
|
|
60
|
+
*/
|
|
61
|
+
findSimilar(nodeId: string, threshold?: number): Array<{
|
|
62
|
+
node: GraphNode;
|
|
63
|
+
similarity: number;
|
|
64
|
+
}>;
|
|
65
|
+
/**
|
|
66
|
+
* Find shortest path between nodes
|
|
67
|
+
*/
|
|
68
|
+
findPath(start: string, end: string): string[] | null;
|
|
69
|
+
/**
|
|
70
|
+
* Calculate cosine similarity between vectors
|
|
71
|
+
*/
|
|
72
|
+
private cosineSimilarity;
|
|
73
|
+
/**
|
|
74
|
+
* Get graph statistics
|
|
75
|
+
*/
|
|
76
|
+
getStats(): {
|
|
77
|
+
nodeCount: number;
|
|
78
|
+
edgeCount: number;
|
|
79
|
+
avgEdgesPerNode: number;
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Clear the graph
|
|
83
|
+
*/
|
|
84
|
+
clear(): void;
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=semantic-edge-graph.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"semantic-edge-graph.d.ts","sourceRoot":"","sources":["../../src/memory/semantic-edge-graph.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,SAAS,GAAG,MAAM,GAAG,QAAQ,GAAG,cAAc,CAAC;IACrD,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC9B,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;CACtB;AAED,MAAM,WAAW,SAAS;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC/B;AAED,MAAM,WAAW,uBAAuB;IACtC,eAAe,EAAE,MAAM,CAAC;IACxB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,SAAS,EAAE,MAAM,CAAC;CACnB;AAQD;;;GAGG;AACH,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,MAAM,CAA0B;IACxC,OAAO,CAAC,KAAK,CAAqC;IAClD,OAAO,CAAC,KAAK,CA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
|
+
maxEdgesPerNode: 50,
|
|
8
|
+
similarityThreshold: 0.7,
|
|
9
|
+
decayRate: 0.95,
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Semantic Edge Graph
|
|
13
|
+
* A knowledge graph with semantic connections between nodes
|
|
14
|
+
*/
|
|
15
|
+
export class SemanticEdgeGraph {
|
|
16
|
+
config;
|
|
17
|
+
nodes = new Map();
|
|
18
|
+
edges = new Map();
|
|
19
|
+
constructor(config = {}) {
|
|
20
|
+
this.config = { ...DEFAULT_CONFIG, ...config };
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Add a node to the graph
|
|
24
|
+
*/
|
|
25
|
+
addNode(node) {
|
|
26
|
+
this.nodes.set(node.id, node);
|
|
27
|
+
if (!this.edges.has(node.id)) {
|
|
28
|
+
this.edges.set(node.id, []);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Add an edge between nodes
|
|
33
|
+
*/
|
|
34
|
+
addEdge(source, target, type, weight = 1.0) {
|
|
35
|
+
if (!this.nodes.has(source) || !this.nodes.has(target)) {
|
|
36
|
+
throw new Error(`Nodes ${source} and ${target} must exist`);
|
|
37
|
+
}
|
|
38
|
+
const edge = {
|
|
39
|
+
source,
|
|
40
|
+
target,
|
|
41
|
+
type,
|
|
42
|
+
weight,
|
|
43
|
+
metadata: {},
|
|
44
|
+
};
|
|
45
|
+
// Add edge to both nodes' adjacency lists (undirected)
|
|
46
|
+
this.addEdgeToAdjacency(source, target, edge);
|
|
47
|
+
this.addEdgeToAdjacency(target, source, { ...edge, source: target, target });
|
|
48
|
+
}
|
|
49
|
+
addEdgeToAdjacency(nodeId, targetId, edge) {
|
|
50
|
+
const adj = this.edges.get(nodeId) || [];
|
|
51
|
+
// Remove existing edge if it exists
|
|
52
|
+
const filtered = adj.filter((e) => e.target !== targetId);
|
|
53
|
+
// Add new edge
|
|
54
|
+
filtered.push(edge);
|
|
55
|
+
// Sort by weight and limit
|
|
56
|
+
filtered.sort((a, b) => b.weight - a.weight);
|
|
57
|
+
if (filtered.length > this.config.maxEdgesPerNode) {
|
|
58
|
+
filtered.length = this.config.maxEdgesPerNode;
|
|
59
|
+
}
|
|
60
|
+
this.edges.set(nodeId, filtered);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Get neighbors of a node
|
|
64
|
+
*/
|
|
65
|
+
getNeighbors(nodeId, limit) {
|
|
66
|
+
const adj = this.edges.get(nodeId) || [];
|
|
67
|
+
if (limit) {
|
|
68
|
+
return adj.slice(0, limit).map((e) => ({ nodeId: e.target, edge: e }));
|
|
69
|
+
}
|
|
70
|
+
return adj.map((e) => ({ nodeId: e.target, edge: e }));
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Get all nodes
|
|
74
|
+
*/
|
|
75
|
+
getAllNodes() {
|
|
76
|
+
return Array.from(this.nodes.values());
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Get a node by ID
|
|
80
|
+
*/
|
|
81
|
+
getNode(nodeId) {
|
|
82
|
+
return this.nodes.get(nodeId) || null;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Find similar nodes by content
|
|
86
|
+
*/
|
|
87
|
+
findSimilar(nodeId, threshold = 0.7) {
|
|
88
|
+
const node = this.nodes.get(nodeId);
|
|
89
|
+
if (!node || !node.embedding) {
|
|
90
|
+
return [];
|
|
91
|
+
}
|
|
92
|
+
const results = [];
|
|
93
|
+
for (const [id, otherNode] of this.nodes) {
|
|
94
|
+
if (id === nodeId || !otherNode.embedding)
|
|
95
|
+
continue;
|
|
96
|
+
const similarity = this.cosineSimilarity(node.embedding, otherNode.embedding);
|
|
97
|
+
if (similarity >= threshold) {
|
|
98
|
+
results.push({ node: otherNode, similarity });
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return results.sort((a, b) => b.similarity - a.similarity);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Find shortest path between nodes
|
|
105
|
+
*/
|
|
106
|
+
findPath(start, end) {
|
|
107
|
+
if (!this.nodes.has(start) || !this.nodes.has(end)) {
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
const visited = new Set();
|
|
111
|
+
const queue = [{ node: start, path: [start] }];
|
|
112
|
+
while (queue.length > 0) {
|
|
113
|
+
const { node, path } = queue.shift();
|
|
114
|
+
if (node === end) {
|
|
115
|
+
return path;
|
|
116
|
+
}
|
|
117
|
+
if (visited.has(node))
|
|
118
|
+
continue;
|
|
119
|
+
visited.add(node);
|
|
120
|
+
const neighbors = this.getNeighbors(node);
|
|
121
|
+
for (const { nodeId: neighborId } of neighbors) {
|
|
122
|
+
if (!visited.has(neighborId)) {
|
|
123
|
+
queue.push({ node: neighborId, path: [...path, neighborId] });
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Calculate cosine similarity between vectors
|
|
131
|
+
*/
|
|
132
|
+
cosineSimilarity(a, b) {
|
|
133
|
+
if (a.length !== b.length || a.length === 0)
|
|
134
|
+
return 0;
|
|
135
|
+
let dotProduct = 0;
|
|
136
|
+
let normA = 0;
|
|
137
|
+
let normB = 0;
|
|
138
|
+
for (let i = 0; i < a.length; i++) {
|
|
139
|
+
dotProduct += a[i] * b[i];
|
|
140
|
+
normA += a[i] * a[i];
|
|
141
|
+
normB += b[i] * b[i];
|
|
142
|
+
}
|
|
143
|
+
return dotProduct / (Math.sqrt(normA) * Math.sqrt(normB));
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Get graph statistics
|
|
147
|
+
*/
|
|
148
|
+
getStats() {
|
|
149
|
+
const nodeCount = this.nodes.size;
|
|
150
|
+
let edgeCount = 0;
|
|
151
|
+
for (const adj of this.edges.values()) {
|
|
152
|
+
edgeCount += adj.length;
|
|
153
|
+
}
|
|
154
|
+
return {
|
|
155
|
+
nodeCount,
|
|
156
|
+
edgeCount,
|
|
157
|
+
avgEdgesPerNode: nodeCount > 0 ? edgeCount / nodeCount : 0,
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Clear the graph
|
|
162
|
+
*/
|
|
163
|
+
clear() {
|
|
164
|
+
this.nodes.clear();
|
|
165
|
+
this.edges.clear();
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
//# sourceMappingURL=semantic-edge-graph.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"semantic-edge-graph.js","sourceRoot":"","sources":["../../src/memory/semantic-edge-graph.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAwBH,MAAM,cAAc,GAA4B;IAC9C,eAAe,EAAE,EAAE;IACnB,mBAAmB,EAAE,GAAG;IACxB,SAAS,EAAE,IAAI;CAChB,CAAC;AAEF;;;GAGG;AACH,MAAM,OAAO,iBAAiB;IACpB,MAAM,CAA0B;IAChC,KAAK,GAA2B,IAAI,GAAG,EAAE,CAAC;IAC1C,KAAK,GAA6B,IAAI,GAAG,EAAE,CAAC;IAEpD,YAAY,SAA2C,EAAE;QACvD,IAAI,CAAC,MAAM,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,MAAM,EAAE,CAAC;IACjD,CAAC;IAED;;OAEG;IACH,OAAO,CAAC,IAAe;QACrB,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;QAC9B,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC;YAC7B,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;QAC9B,CAAC;IACH,CAAC;IAED;;OAEG;IACH,OAAO,CAAC,MAAc,EAAE,MAAc,EAAE,IAAY,EAAE,SAAiB,GAAG;QACxE,IAAI,CAAC,IAAI,CAAC,KAAK,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CAAC;YACtC,SAAS,IAAI,GAAG,CAAC,MAAM,CAAC;QAC1B,CAAC;QAED,OAAO;YACL,SAAS;YACT,SAAS;YACT,eAAe,EAAE,SAAS,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;SAC3D,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;QACnB,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;IACrB,CAAC;CACF"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Semantic Retrieval Module for UAP
|
|
3
|
+
*
|
|
4
|
+
* Implements semantic search over memory entries using embeddings.
|
|
5
|
+
*/
|
|
6
|
+
export interface MemoryEntry {
|
|
7
|
+
id: string;
|
|
8
|
+
content: string;
|
|
9
|
+
type: string;
|
|
10
|
+
timestamp: string;
|
|
11
|
+
importance?: number;
|
|
12
|
+
embedding?: number[];
|
|
13
|
+
}
|
|
14
|
+
export interface SemanticRetrievalConfig {
|
|
15
|
+
minScore: number;
|
|
16
|
+
topK: number;
|
|
17
|
+
embeddingModel: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Semantic Retrieval Manager
|
|
21
|
+
* Provides semantic search capabilities for memory entries
|
|
22
|
+
*/
|
|
23
|
+
export declare class SemanticRetrieval {
|
|
24
|
+
private config;
|
|
25
|
+
private memoryIndex;
|
|
26
|
+
private embeddingService;
|
|
27
|
+
constructor(config?: Partial<SemanticRetrievalConfig>);
|
|
28
|
+
/**
|
|
29
|
+
* Index a memory entry
|
|
30
|
+
*/
|
|
31
|
+
addEntry(entry: MemoryEntry): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Index multiple entries
|
|
34
|
+
*/
|
|
35
|
+
addEntries(entries: MemoryEntry[]): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Remove an entry from the index
|
|
38
|
+
*/
|
|
39
|
+
removeEntry(id: string): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Search for similar entries
|
|
42
|
+
*/
|
|
43
|
+
search(query: string, options?: {
|
|
44
|
+
limit?: number;
|
|
45
|
+
minScore?: number;
|
|
46
|
+
}): Promise<Array<{
|
|
47
|
+
entry: MemoryEntry;
|
|
48
|
+
score: number;
|
|
49
|
+
}>>;
|
|
50
|
+
/**
|
|
51
|
+
* Get an entry by ID
|
|
52
|
+
*/
|
|
53
|
+
getEntry(id: string): MemoryEntry | null;
|
|
54
|
+
/**
|
|
55
|
+
* Get all indexed entries
|
|
56
|
+
*/
|
|
57
|
+
getAllEntries(): MemoryEntry[];
|
|
58
|
+
/**
|
|
59
|
+
* Get index statistics
|
|
60
|
+
*/
|
|
61
|
+
getStats(): {
|
|
62
|
+
indexedCount: number;
|
|
63
|
+
hasEmbeddings: number;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Clear the index
|
|
67
|
+
*/
|
|
68
|
+
clear(): void;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=semantic-retrieval.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"semantic-retrieval.d.ts","sourceRoot":"","sources":["../../src/memory/semantic-retrieval.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;CACtB;AAED,MAAM,WAAW,uBAAuB;IACtC,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,cAAc,EAAE,MAAM,CAAC;CACxB;AAQD;;;GAGG;AACH,qBAAa,iBAAiB;IAC5B,OAAO,CAAC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