@miller-tech/uap 1.5.5 → 1.5.7
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 -1
- package/dist/benchmarks/benchmark.d.ts +53 -53
- 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/coordination/droid-validator.d.ts +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/models/types.d.ts +57 -57
- package/dist/policies/schemas/policy.d.ts +18 -18
- package/dist/tasks/types.d.ts +23 -23
- package/dist/types/config.d.ts +416 -416
- package/dist/types/coordination.d.ts +22 -22
- package/dist/uap-droids-strict.d.ts +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/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 +1 -1
|
@@ -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,UAAU,EAAE,WAAW,EAAE,SAAS,CAAC;KACpE;IACD;QACE,EAAE,EAAE,QAAQ;QACZ,IAAI,EAAE,gBAAgB;QACtB,WAAW,EAAE,6CAA6C;QAC1D,QAAQ,EACN,qJAAqJ;QACvJ,SAAS,EAAE,CAAC,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,CAAC;KACtE;IACD;QACE,EAAE,EAAE,QAAQ;QACZ,IAAI,EAAE,kBAAkB;QACxB,WAAW,EAAE,qCAAqC;QAClD,QAAQ,EACN,yHAAyH;QAC3H,SAA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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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KAAK,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,SAAS,CAAA;KAAE,CAAC;IAUxF;;OAEG;IACH,WAAW,IAAI,SAAS,EAAE;IAI1B;;OAEG;IACH,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI;IAIzC;;OAEG;IACH,WAAW,CACT,MAAM,EAAE,MAAM,EACd,SAAS,GAAE,MAAY,GACtB,KAAK,CAAC;QAAE,IAAI,EAAE,SAAS,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC;IAoBjD;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI;IA6BrD;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAgBxB;;OAEG;IACH,QAAQ,IAAI;QACV,SAAS,EAAE,MAAM,CAAC;QAClB,SAAS,EAAE,MAAM,CAAC;QAClB,eAAe,EAAE,MAAM,CAAC;KACzB;IAeD;;OAEG;IACH,KAAK,IAAI,IAAI;CAId"}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Semantic Edge Graph Module for UAP
|
|
3
|
+
*
|
|
4
|
+
* Implements a knowledge graph with semantic edges for efficient memory retrieval.
|
|
5
|
+
*/
|
|
6
|
+
const DEFAULT_CONFIG = {
|
|
7
|
+
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":"","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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,MAAM,CAA0B;IACxC,OAAO,CAAC,WAAW,CAAuC;IAC1D,OAAO,CAAC,gBAAgB,CAAyB;gBAErC,MAAM,GAAE,OAAO,CAAC,uBAAuB,CAAM;IAIzD;;OAEG;IACG,QAAQ,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAajD;;OAEG;IACG,UAAU,CAAC,OAAO,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAIvD;;OAEG;IACH,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;IAIhC;;OAEG;IACG,MAAM,CACV,KAAK,EAAE,MAAM,EACb,OAAO,GAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAO,GAClD,OAAO,CAAC,KAAK,CAAC;QAAE,KAAK,EAAE,WAAW,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IA+BxD;;OAEG;IACH,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI;IAIxC;;OAEG;IACH,aAAa,IAAI,WAAW,EAAE;IAI9B;;OAEG;IACH,QAAQ,IAAI;QACV,YAAY,EAAE,MAAM,CAAC;QACrB,aAAa,EAAE,MAAM,CAAC;KACvB;IAaD;;OAEG;IACH,KAAK,IAAI,IAAI;CAGd"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Semantic Retrieval Module for UAP
|
|
3
|
+
*
|
|
4
|
+
* Implements semantic search over memory entries using embeddings.
|
|
5
|
+
*/
|
|
6
|
+
import { getEmbeddingService } from './embeddings.js';
|
|
7
|
+
const DEFAULT_CONFIG = {
|
|
8
|
+
minScore: 0.5,
|
|
9
|
+
topK: 10,
|
|
10
|
+
embeddingModel: 'default',
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Semantic Retrieval Manager
|
|
14
|
+
* Provides semantic search capabilities for memory entries
|
|
15
|
+
*/
|
|
16
|
+
export class SemanticRetrieval {
|
|
17
|
+
config;
|
|
18
|
+
memoryIndex = new Map();
|
|
19
|
+
embeddingService = getEmbeddingService();
|
|
20
|
+
constructor(config = {}) {
|
|
21
|
+
this.config = { ...DEFAULT_CONFIG, ...config };
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Index a memory entry
|
|
25
|
+
*/
|
|
26
|
+
async addEntry(entry) {
|
|
27
|
+
// Generate embedding if not provided
|
|
28
|
+
if (!entry.embedding) {
|
|
29
|
+
try {
|
|
30
|
+
entry.embedding = await this.embeddingService.embed(entry.content);
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
console.warn('Failed to embed content:', error);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
this.memoryIndex.set(entry.id, entry);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Index multiple entries
|
|
40
|
+
*/
|
|
41
|
+
async addEntries(entries) {
|
|
42
|
+
await Promise.all(entries.map((e) => this.addEntry(e)));
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Remove an entry from the index
|
|
46
|
+
*/
|
|
47
|
+
removeEntry(id) {
|
|
48
|
+
return this.memoryIndex.delete(id);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Search for similar entries
|
|
52
|
+
*/
|
|
53
|
+
async search(query, options = {}) {
|
|
54
|
+
const limit = options.limit || this.config.topK;
|
|
55
|
+
const minScore = options.minScore ?? this.config.minScore;
|
|
56
|
+
// Embed the query
|
|
57
|
+
let queryEmbedding;
|
|
58
|
+
try {
|
|
59
|
+
queryEmbedding = await this.embeddingService.embed(query);
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
console.warn('Failed to embed query:', error);
|
|
63
|
+
return [];
|
|
64
|
+
}
|
|
65
|
+
// Search index
|
|
66
|
+
const results = [];
|
|
67
|
+
for (const entry of this.memoryIndex.values()) {
|
|
68
|
+
if (!entry.embedding)
|
|
69
|
+
continue;
|
|
70
|
+
const score = this.embeddingService.cosineSimilarity(queryEmbedding, entry.embedding);
|
|
71
|
+
if (score >= minScore) {
|
|
72
|
+
results.push({ entry, score });
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
// Sort by score and limit
|
|
76
|
+
results.sort((a, b) => b.score - a.score);
|
|
77
|
+
return results.slice(0, limit);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Get an entry by ID
|
|
81
|
+
*/
|
|
82
|
+
getEntry(id) {
|
|
83
|
+
return this.memoryIndex.get(id) || null;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Get all indexed entries
|
|
87
|
+
*/
|
|
88
|
+
getAllEntries() {
|
|
89
|
+
return Array.from(this.memoryIndex.values());
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Get index statistics
|
|
93
|
+
*/
|
|
94
|
+
getStats() {
|
|
95
|
+
let hasEmbeddings = 0;
|
|
96
|
+
for (const entry of this.memoryIndex.values()) {
|
|
97
|
+
if (entry.embedding)
|
|
98
|
+
hasEmbeddings++;
|
|
99
|
+
}
|
|
100
|
+
return {
|
|
101
|
+
indexedCount: this.memoryIndex.size,
|
|
102
|
+
hasEmbeddings,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Clear the index
|
|
107
|
+
*/
|
|
108
|
+
clear() {
|
|
109
|
+
this.memoryIndex.clear();
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=semantic-retrieval.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"semantic-retrieval.js","sourceRoot":"","sources":["../../src/memory/semantic-retrieval.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAiBtD,MAAM,cAAc,GAA4B;IAC9C,QAAQ,EAAE,GAAG;IACb,IAAI,EAAE,EAAE;IACR,cAAc,EAAE,SAAS;CAC1B,CAAC;AAEF;;;GAGG;AACH,MAAM,OAAO,iBAAiB;IACpB,MAAM,CAA0B;IAChC,WAAW,GAA6B,IAAI,GAAG,EAAE,CAAC;IAClD,gBAAgB,GAAG,mBAAmB,EAAE,CAAC;IAEjD,YAAY,SAA2C,EAAE;QACvD,IAAI,CAAC,MAAM,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,MAAM,EAAE,CAAC;IACjD,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,QAAQ,CAA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ACH,KAAK;QACH,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;IAC3B,CAAC;CACF"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Smart Consolidator Module for UAP
|
|
3
|
+
*
|
|
4
|
+
* Implements intelligent memory consolidation based on relevance, recency, and patterns.
|
|
5
|
+
*/
|
|
6
|
+
export interface MemoryEntry {
|
|
7
|
+
id: string;
|
|
8
|
+
content: string;
|
|
9
|
+
type: string;
|
|
10
|
+
timestamp: string;
|
|
11
|
+
importance?: number;
|
|
12
|
+
}
|
|
13
|
+
export interface ConsolidationConfig {
|
|
14
|
+
minEntriesToConsolidate: number;
|
|
15
|
+
maxTokensPerSummary: number;
|
|
16
|
+
similarityThreshold: number;
|
|
17
|
+
priorityBy: 'importance' | 'recency' | 'relevance';
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Smart Consolidator
|
|
21
|
+
* Intelligently consolidates related memories into summaries
|
|
22
|
+
*/
|
|
23
|
+
export declare class SmartConsolidator {
|
|
24
|
+
private config;
|
|
25
|
+
constructor(config?: Partial<ConsolidationConfig>);
|
|
26
|
+
/**
|
|
27
|
+
* Consolidate a batch of memories into summaries
|
|
28
|
+
*/
|
|
29
|
+
consolidate(memories: MemoryEntry[]): Array<{
|
|
30
|
+
summary: string;
|
|
31
|
+
sourceIds: string[];
|
|
32
|
+
}>;
|
|
33
|
+
/**
|
|
34
|
+
* Get consolidation recommendations for a batch of memories
|
|
35
|
+
*/
|
|
36
|
+
getRecommendations(memories: MemoryEntry[]): Array<{
|
|
37
|
+
ids: string[];
|
|
38
|
+
reason: string;
|
|
39
|
+
}>;
|
|
40
|
+
/**
|
|
41
|
+
* Group similar memories together
|
|
42
|
+
*/
|
|
43
|
+
private groupSimilarMemories;
|
|
44
|
+
/**
|
|
45
|
+
* Check if two pieces of content are similar
|
|
46
|
+
*/
|
|
47
|
+
private areSimilar;
|
|
48
|
+
/**
|
|
49
|
+
* Generate a summary from multiple memories
|
|
50
|
+
*/
|
|
51
|
+
private generateSummary;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=smart-consolidator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"smart-consolidator.d.ts","sourceRoot":"","sources":["../../src/memory/smart-consolidator.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;CACrB;AAED,MAAM,WAAW,mBAAmB;IAClC,uBAAuB,EAAE,MAAM,CAAC;IAChC,mBAAmB,EAAE,MAAM,CAAC;IAC5B,mBAAmB,EAAE,MAAM,CAAC;IAC5B,UAAU,EAAE,YAAY,GAAG,SAAS,GAAG,WAAW,CAAC;CACpD;AASD;;;GAGG;AACH,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,MAAM,CAAsB;gBAExB,MAAM,GAAE,OAAO,CAAC,mBAAmB,CAAM;IAIrD;;OAEG;IACH,WAAW,CAAC,QAAQ,EAAE,WAAW,EAAE,GAAG,KAAK,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC;IA8BrF;;OAEG;IACH,kBAAkB,CAAC,QAAQ,EAAE,WAAW,EAAE,GAAG,KAAK,CAAC;QAAE,GAAG,EAAE,MAAM,EAAE,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IAgBrF;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAyB5B;;OAEG;IACH,OAAO,CAAC,UAAU;IAoBlB;;OAEG;IACH,OAAO,CAAC,eAAe;CAkCxB"}
|