@elizaos/plugin-rolodex 2.0.0-alpha.3
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/__tests__/test-utils.d.ts +5 -0
- package/dist/actions/addContact.d.ts +2 -0
- package/dist/actions/index.d.ts +7 -0
- package/dist/actions/removeContact.d.ts +2 -0
- package/dist/actions/scheduleFollowUp.d.ts +2 -0
- package/dist/actions/searchContacts.d.ts +2 -0
- package/dist/actions/sendMessage.d.ts +14 -0
- package/dist/actions/updateContact.d.ts +2 -0
- package/dist/actions/updateEntity.d.ts +42 -0
- package/dist/evaluators/index.d.ts +3 -0
- package/dist/evaluators/reflection.d.ts +2 -0
- package/dist/evaluators/relationshipExtraction.d.ts +16 -0
- package/dist/frontend/utils.d.ts +2 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +9759 -0
- package/dist/index.js.map +49 -0
- package/dist/providers/contacts.d.ts +2 -0
- package/dist/providers/facts.d.ts +10 -0
- package/dist/providers/followUps.d.ts +2 -0
- package/dist/providers/index.d.ts +4 -0
- package/dist/providers/relationships.d.ts +11 -0
- package/dist/services/EntityResolutionService.d.ts +76 -0
- package/dist/services/FollowUpService.d.ts +37 -0
- package/dist/services/RolodexService.d.ts +73 -0
- package/dist/services/index.d.ts +3 -0
- package/dist/tests/ConversationSimulator.d.ts +71 -0
- package/dist/tests/ScenarioVerifier.d.ts +59 -0
- package/dist/tests/e2e.test.d.ts +2 -0
- package/dist/tests/entity-graph.test.d.ts +2 -0
- package/dist/tests/index.d.ts +6 -0
- package/dist/tests/scenarios.test.d.ts +9 -0
- package/dist/types/index.d.ts +281 -0
- package/dist/utils/graphTraversal.d.ts +86 -0
- package/dist/utils/relationshipStrength.d.ts +16 -0
- package/dist/utils/similarity.d.ts +58 -0
- package/dist/utils/timeWeighting.d.ts +64 -0
- package/package.json +49 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Graph traversal utilities for the entity relationship graph.
|
|
3
|
+
*
|
|
4
|
+
* Operates on an adjacency-list representation built from the
|
|
5
|
+
* runtime's relationship data. All traversals are bounded to
|
|
6
|
+
* prevent runaway computation on large graphs.
|
|
7
|
+
*/
|
|
8
|
+
import type { Relationship, UUID } from "@elizaos/core";
|
|
9
|
+
/**
|
|
10
|
+
* An adjacency-list graph built from relationships.
|
|
11
|
+
* Maps entityId -> Set of connected entityIds.
|
|
12
|
+
*/
|
|
13
|
+
export type AdjacencyGraph = Map<UUID, Set<UUID>>;
|
|
14
|
+
/**
|
|
15
|
+
* Build an adjacency graph from a list of relationships.
|
|
16
|
+
* Relationships are treated as undirected edges.
|
|
17
|
+
*/
|
|
18
|
+
export declare function buildAdjacencyGraph(relationships: Relationship[]): AdjacencyGraph;
|
|
19
|
+
/**
|
|
20
|
+
* Get the N-hop neighborhood of an entity.
|
|
21
|
+
*
|
|
22
|
+
* This is the key operation for small-world entity resolution: instead
|
|
23
|
+
* of scanning all entities, we only compare against entities within
|
|
24
|
+
* a few hops. In small-world networks, 2-3 hops covers the relevant
|
|
25
|
+
* local cluster.
|
|
26
|
+
*
|
|
27
|
+
* @param graph The adjacency graph.
|
|
28
|
+
* @param start The starting entity.
|
|
29
|
+
* @param hops Maximum number of hops (default 2).
|
|
30
|
+
* @param maxNodes Maximum nodes to return (safety bound, default 200).
|
|
31
|
+
* @returns Set of entity IDs within the neighborhood (excluding start).
|
|
32
|
+
*/
|
|
33
|
+
export declare function getNeighborhood(graph: AdjacencyGraph, start: UUID, hops?: number, maxNodes?: number): Set<UUID>;
|
|
34
|
+
/**
|
|
35
|
+
* Find the shortest path between two entities using BFS.
|
|
36
|
+
*
|
|
37
|
+
* @returns Array of entity IDs forming the path, or null if no path exists.
|
|
38
|
+
* Includes both start and end.
|
|
39
|
+
*/
|
|
40
|
+
export declare function shortestPath(graph: AdjacencyGraph, start: UUID, end: UUID, maxDepth?: number): UUID[] | null;
|
|
41
|
+
/**
|
|
42
|
+
* Get shared connections between two entities.
|
|
43
|
+
*
|
|
44
|
+
* @returns Set of entity IDs that are directly connected to both A and B.
|
|
45
|
+
*/
|
|
46
|
+
export declare function sharedConnections(graph: AdjacencyGraph, entityA: UUID, entityB: UUID): Set<UUID>;
|
|
47
|
+
/**
|
|
48
|
+
* Compute degree centrality for all nodes (number of direct connections).
|
|
49
|
+
* Returns nodes sorted by degree descending.
|
|
50
|
+
*/
|
|
51
|
+
export declare function degreeCentrality(graph: AdjacencyGraph): Array<{
|
|
52
|
+
entityId: UUID;
|
|
53
|
+
degree: number;
|
|
54
|
+
}>;
|
|
55
|
+
/**
|
|
56
|
+
* Detect clusters / communities using a simple label propagation approach.
|
|
57
|
+
*
|
|
58
|
+
* Each node starts with its own label. In each iteration, nodes adopt the
|
|
59
|
+
* most common label among their neighbors. Converges when labels stabilize.
|
|
60
|
+
*
|
|
61
|
+
* This is O(V + E) per iteration and typically converges in 3-5 iterations
|
|
62
|
+
* for small-world graphs.
|
|
63
|
+
*
|
|
64
|
+
* @param graph The adjacency graph.
|
|
65
|
+
* @param maxIter Maximum iterations (default 10).
|
|
66
|
+
* @returns Map of entityId -> clusterId.
|
|
67
|
+
*/
|
|
68
|
+
export declare function detectClusters(graph: AdjacencyGraph, maxIter?: number): Map<UUID, string>;
|
|
69
|
+
/**
|
|
70
|
+
* Get all entities in the same cluster as the given entity.
|
|
71
|
+
*/
|
|
72
|
+
export declare function getClusterMembers(clusters: Map<UUID, string>, entityId: UUID): UUID[];
|
|
73
|
+
/**
|
|
74
|
+
* Compute a simple "influence score" for an entity based on:
|
|
75
|
+
* - Degree centrality (how many connections)
|
|
76
|
+
* - Betweenness approximation (how many shortest paths pass through)
|
|
77
|
+
*
|
|
78
|
+
* The betweenness is approximated by sampling rather than computing
|
|
79
|
+
* all-pairs shortest paths (which is O(V^3)).
|
|
80
|
+
*
|
|
81
|
+
* @param graph The adjacency graph.
|
|
82
|
+
* @param entityId The entity to score.
|
|
83
|
+
* @param sampleSize Number of random pairs to sample for betweenness.
|
|
84
|
+
* @returns Influence score 0-1.
|
|
85
|
+
*/
|
|
86
|
+
export declare function influenceScore(graph: AdjacencyGraph, entityId: UUID, sampleSize?: number): number;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculate relationship strength based on interaction patterns
|
|
3
|
+
*
|
|
4
|
+
* @param {Object} params - Parameters for calculating relationship strength
|
|
5
|
+
* @param {number} params.interactionCount - Total number of interactions
|
|
6
|
+
* @param {string} params.lastInteractionAt - ISO timestamp of last interaction
|
|
7
|
+
* @param {number} params.messageQuality - Average quality score of messages (0-10)
|
|
8
|
+
* @param {string} params.relationshipType - Type of relationship
|
|
9
|
+
* @returns {number} Relationship strength score (0-100)
|
|
10
|
+
*/
|
|
11
|
+
export declare function calculateRelationshipStrength({ interactionCount, lastInteractionAt, messageQuality, relationshipType, }: {
|
|
12
|
+
interactionCount: number;
|
|
13
|
+
lastInteractionAt?: string;
|
|
14
|
+
messageQuality?: number;
|
|
15
|
+
relationshipType?: string;
|
|
16
|
+
}): number;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Similarity and matching utilities for entity resolution.
|
|
3
|
+
*
|
|
4
|
+
* These are intentionally lightweight – no external NLP dependencies.
|
|
5
|
+
* The heavy lifting is done by the LLM; these provide fast pre-filters
|
|
6
|
+
* for candidate generation in the small-world neighborhood scan.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Normalized Levenshtein distance between two strings.
|
|
10
|
+
*
|
|
11
|
+
* @returns A similarity score 0-1 where 1 means identical.
|
|
12
|
+
*/
|
|
13
|
+
export declare function nameSimilarity(a: string, b: string): number;
|
|
14
|
+
/**
|
|
15
|
+
* Check whether two handles correlate across platforms.
|
|
16
|
+
*
|
|
17
|
+
* Strips common prefixes (@), normalizes case, and compares the
|
|
18
|
+
* underlying username. Also checks for common patterns like
|
|
19
|
+
* "dave_codes" matching "davecodes" matching "dave-codes".
|
|
20
|
+
*
|
|
21
|
+
* @returns Similarity score 0-1.
|
|
22
|
+
*/
|
|
23
|
+
export declare function handleCorrelation(handleA: string, handleB: string): number;
|
|
24
|
+
/**
|
|
25
|
+
* Normalize a handle by stripping @, removing separators, lowering case.
|
|
26
|
+
*/
|
|
27
|
+
export declare function normalizeHandle(handle: string): string;
|
|
28
|
+
/**
|
|
29
|
+
* Jaccard similarity between two sets.
|
|
30
|
+
*
|
|
31
|
+
* Used for comparing shared connections, shared rooms, shared topics.
|
|
32
|
+
*
|
|
33
|
+
* @returns Score 0-1 where 1 means identical sets.
|
|
34
|
+
*/
|
|
35
|
+
export declare function jaccardSimilarity<T>(setA: Set<T>, setB: Set<T>): number;
|
|
36
|
+
/**
|
|
37
|
+
* Check if two names could be nicknames / variations of each other.
|
|
38
|
+
*
|
|
39
|
+
* Handles common patterns:
|
|
40
|
+
* - "Dave" / "David"
|
|
41
|
+
* - "TechGuru" / "Tech Guru"
|
|
42
|
+
* - First name matching when one side has full name
|
|
43
|
+
*
|
|
44
|
+
* @returns Similarity score 0-1.
|
|
45
|
+
*/
|
|
46
|
+
export declare function nameVariationMatch(nameA: string, nameB: string): number;
|
|
47
|
+
/**
|
|
48
|
+
* Extract the "base" username from a handle, stripping common suffixes
|
|
49
|
+
* like platform markers (_dev, _eth, _nft) and numbers.
|
|
50
|
+
*/
|
|
51
|
+
export declare function extractBaseUsername(handle: string): string;
|
|
52
|
+
/**
|
|
53
|
+
* Quick check: could these two strings plausibly refer to the same
|
|
54
|
+
* entity? Used as a fast pre-filter before more expensive analysis.
|
|
55
|
+
*
|
|
56
|
+
* @returns true if there's enough signal to warrant deeper comparison.
|
|
57
|
+
*/
|
|
58
|
+
export declare function couldBeSameEntity(nameA: string, nameB: string): boolean;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Time-weighted confidence decay.
|
|
3
|
+
*
|
|
4
|
+
* Based on the Ebbinghaus forgetting curve, adapted for information
|
|
5
|
+
* reliability: confidence decays with a configurable half-life, and
|
|
6
|
+
* corroborations increase stability (each corroboration doubles the
|
|
7
|
+
* effective half-life).
|
|
8
|
+
*
|
|
9
|
+
* Formula: confidence(t) = baseConfidence * 0.5^(elapsed / effectiveHalfLife)
|
|
10
|
+
*
|
|
11
|
+
* References:
|
|
12
|
+
* - Ebbinghaus, H. (1885). Memory: A Contribution to Experimental Psychology.
|
|
13
|
+
* - Leitner spaced-repetition stability model.
|
|
14
|
+
*/
|
|
15
|
+
import type { InformationClaim } from "../types/index";
|
|
16
|
+
/**
|
|
17
|
+
* Compute the current confidence of a claim, accounting for time decay
|
|
18
|
+
* and corroboration stability.
|
|
19
|
+
*
|
|
20
|
+
* @param claim The information claim to evaluate.
|
|
21
|
+
* @param now Current timestamp (ms). Defaults to Date.now().
|
|
22
|
+
* @returns The decayed confidence, clamped to [0, 1].
|
|
23
|
+
*/
|
|
24
|
+
export declare function computeDecayedConfidence(claim: InformationClaim, now?: number): number;
|
|
25
|
+
/**
|
|
26
|
+
* Each corroboration doubles the half-life, making information stickier
|
|
27
|
+
* the more people confirm it. Disputes halve it.
|
|
28
|
+
*
|
|
29
|
+
* effectiveHalfLife = halfLifeMs * 2^(corroborations - unresolvedDisputes)
|
|
30
|
+
*
|
|
31
|
+
* Clamped so it never drops below 1 day or exceeds 365 days (unless
|
|
32
|
+
* the base half-life is already Infinity for ground truth).
|
|
33
|
+
*/
|
|
34
|
+
export declare function getEffectiveHalfLife(claim: InformationClaim): number;
|
|
35
|
+
/**
|
|
36
|
+
* Compute decayed relationship strength.
|
|
37
|
+
*
|
|
38
|
+
* Uses the same half-life model: strength decays from its base value
|
|
39
|
+
* since the last interaction.
|
|
40
|
+
*
|
|
41
|
+
* @param baseStrength The strength at last interaction (0-100).
|
|
42
|
+
* @param lastInteractionAt ISO timestamp of last interaction.
|
|
43
|
+
* @param halfLifeMs Decay half-life in ms.
|
|
44
|
+
* @param now Current timestamp.
|
|
45
|
+
* @returns Decayed strength (0-100).
|
|
46
|
+
*/
|
|
47
|
+
export declare function computeRelationshipDecay(baseStrength: number, lastInteractionAt: string | undefined, halfLifeMs: number, now?: number): number;
|
|
48
|
+
/**
|
|
49
|
+
* Compute a new base confidence after a corroboration event.
|
|
50
|
+
*
|
|
51
|
+
* Each corroboration nudges the base confidence upward using a
|
|
52
|
+
* diminishing-returns formula:
|
|
53
|
+
* newBase = oldBase + (1 - oldBase) * boostFactor
|
|
54
|
+
*
|
|
55
|
+
* where boostFactor decreases with each successive corroboration.
|
|
56
|
+
*/
|
|
57
|
+
export declare function boostConfidenceFromCorroboration(currentBase: number, corroborationCount: number): number;
|
|
58
|
+
/**
|
|
59
|
+
* Reduce confidence when a dispute is filed.
|
|
60
|
+
*
|
|
61
|
+
* Drops base confidence by a penalty that scales with how many unresolved
|
|
62
|
+
* disputes exist vs corroborations.
|
|
63
|
+
*/
|
|
64
|
+
export declare function penalizeConfidenceFromDispute(currentBase: number, unresolvedDisputeCount: number, corroborationCount: number): number;
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@elizaos/plugin-rolodex",
|
|
3
|
+
"version": "2.0.0-alpha.3",
|
|
4
|
+
"description": "A plugin for ElizaOS that allows you to manage entites, relationships and associations",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "bun run build.ts",
|
|
20
|
+
"dev": "bun run build.ts --watch",
|
|
21
|
+
"test": "elizaos test",
|
|
22
|
+
"clean": "rm -rf dist .turbo node_modules",
|
|
23
|
+
"lint": "bunx @biomejs/biome check --write --unsafe .",
|
|
24
|
+
"lint:check": "bunx @biomejs/biome check .",
|
|
25
|
+
"format": "bunx @biomejs/biome format --write .",
|
|
26
|
+
"format:check": "bunx @biomejs/biome format .",
|
|
27
|
+
"typecheck": "tsc --noEmit"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@elizaos/core": "2.0.0-alpha.3",
|
|
31
|
+
"clsx": "^2.1.1",
|
|
32
|
+
"tailwind-merge": "^3.4.0"
|
|
33
|
+
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"whatwg-url": "7.1.0"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@types/node": "^22.15.3",
|
|
39
|
+
"tailwindcss": "^4.1.10",
|
|
40
|
+
"tsup": "8.5.0",
|
|
41
|
+
"vite": "^6.3.5",
|
|
42
|
+
"vitest": "3.1.4",
|
|
43
|
+
"zod": "^3.22.4",
|
|
44
|
+
"@biomejs/biome": "^2.3.11"
|
|
45
|
+
},
|
|
46
|
+
"publishConfig": {
|
|
47
|
+
"access": "public"
|
|
48
|
+
}
|
|
49
|
+
}
|