@lawrenceliang-btc/atel-sdk 0.8.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/LICENSE +21 -0
- package/README.md +221 -0
- package/bin/atel.mjs +2692 -0
- package/bin/tunnel-manager.mjs +171 -0
- package/dist/anchor/base.d.ts +21 -0
- package/dist/anchor/base.js +26 -0
- package/dist/anchor/bsc.d.ts +20 -0
- package/dist/anchor/bsc.js +25 -0
- package/dist/anchor/evm.d.ts +99 -0
- package/dist/anchor/evm.js +262 -0
- package/dist/anchor/index.d.ts +173 -0
- package/dist/anchor/index.js +165 -0
- package/dist/anchor/mock.d.ts +43 -0
- package/dist/anchor/mock.js +100 -0
- package/dist/anchor/solana.d.ts +95 -0
- package/dist/anchor/solana.js +298 -0
- package/dist/auditor/index.d.ts +54 -0
- package/dist/auditor/index.js +141 -0
- package/dist/collaboration/index.d.ts +146 -0
- package/dist/collaboration/index.js +237 -0
- package/dist/crypto/index.d.ts +162 -0
- package/dist/crypto/index.js +231 -0
- package/dist/endpoint/index.d.ts +147 -0
- package/dist/endpoint/index.js +390 -0
- package/dist/envelope/index.d.ts +104 -0
- package/dist/envelope/index.js +156 -0
- package/dist/executor/index.d.ts +71 -0
- package/dist/executor/index.js +398 -0
- package/dist/gateway/index.d.ts +278 -0
- package/dist/gateway/index.js +520 -0
- package/dist/graph/index.d.ts +215 -0
- package/dist/graph/index.js +524 -0
- package/dist/handshake/index.d.ts +166 -0
- package/dist/handshake/index.js +287 -0
- package/dist/identity/index.d.ts +155 -0
- package/dist/identity/index.js +250 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +28 -0
- package/dist/negotiation/index.d.ts +133 -0
- package/dist/negotiation/index.js +160 -0
- package/dist/network/index.d.ts +78 -0
- package/dist/network/index.js +207 -0
- package/dist/orchestrator/index.d.ts +190 -0
- package/dist/orchestrator/index.js +297 -0
- package/dist/policy/index.d.ts +100 -0
- package/dist/policy/index.js +206 -0
- package/dist/proof/index.d.ts +220 -0
- package/dist/proof/index.js +541 -0
- package/dist/registry/index.d.ts +98 -0
- package/dist/registry/index.js +129 -0
- package/dist/rollback/index.d.ts +76 -0
- package/dist/rollback/index.js +91 -0
- package/dist/schema/capability-schema.json +52 -0
- package/dist/schema/index.d.ts +128 -0
- package/dist/schema/index.js +163 -0
- package/dist/schema/task-schema.json +69 -0
- package/dist/score/index.d.ts +174 -0
- package/dist/score/index.js +275 -0
- package/dist/service/index.d.ts +34 -0
- package/dist/service/index.js +273 -0
- package/dist/service/server.d.ts +7 -0
- package/dist/service/server.js +22 -0
- package/dist/trace/index.d.ts +217 -0
- package/dist/trace/index.js +446 -0
- package/dist/trust/index.d.ts +84 -0
- package/dist/trust/index.js +107 -0
- package/dist/trust-sync/index.d.ts +30 -0
- package/dist/trust-sync/index.js +57 -0
- package/package.json +71 -0
- package/skill/SKILL.md +363 -0
- package/skill/references/commercial.md +184 -0
- package/skill/references/executor.md +356 -0
- package/skill/references/networking.md +64 -0
- package/skill/references/onchain.md +73 -0
- package/skill/references/security.md +96 -0
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Module 8: Trust Graph
|
|
3
|
+
*
|
|
4
|
+
* Multi-dimensional trust graph tracking agent collaboration,
|
|
5
|
+
* scene performance, and trust propagation.
|
|
6
|
+
*
|
|
7
|
+
* Core formulas:
|
|
8
|
+
* DirectTrust(A,B,scene) = success_weighted_rate × recency × consistency × confidence
|
|
9
|
+
* IndirectTrust(A,C) = max path trust × hop_decay^(hops-1)
|
|
10
|
+
* CompositeTrust = α·Direct + β·Indirect + γ·ReputationBonus
|
|
11
|
+
*/
|
|
12
|
+
/** Graph node representing an Agent */
|
|
13
|
+
export interface GraphNode {
|
|
14
|
+
agent_id: string;
|
|
15
|
+
registered_at: string;
|
|
16
|
+
total_interactions: number;
|
|
17
|
+
scenes: Set<string>;
|
|
18
|
+
metadata?: Record<string, any>;
|
|
19
|
+
}
|
|
20
|
+
/** Collaboration edge between two Agents in a specific scene */
|
|
21
|
+
export interface GraphEdge {
|
|
22
|
+
from: string;
|
|
23
|
+
to: string;
|
|
24
|
+
scene: string;
|
|
25
|
+
total_tasks: number;
|
|
26
|
+
successful_tasks: number;
|
|
27
|
+
failed_tasks: number;
|
|
28
|
+
total_weight: number;
|
|
29
|
+
successful_weight: number;
|
|
30
|
+
avg_duration_ms: number;
|
|
31
|
+
last_interaction: string;
|
|
32
|
+
consistency_score: number;
|
|
33
|
+
}
|
|
34
|
+
/** Trust query result */
|
|
35
|
+
export interface TrustResult {
|
|
36
|
+
trust_score: number;
|
|
37
|
+
confidence: number;
|
|
38
|
+
source: 'direct' | 'indirect' | 'composite';
|
|
39
|
+
path?: string[];
|
|
40
|
+
details: {
|
|
41
|
+
direct_trust?: number;
|
|
42
|
+
indirect_trust?: number;
|
|
43
|
+
reputation_bonus?: number;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/** Parameters for task weight calculation */
|
|
47
|
+
export interface TaskWeightParams {
|
|
48
|
+
tool_calls: number;
|
|
49
|
+
duration_ms: number;
|
|
50
|
+
max_cost: number;
|
|
51
|
+
risk_level: 'low' | 'medium' | 'high' | 'critical';
|
|
52
|
+
similar_task_count: number;
|
|
53
|
+
}
|
|
54
|
+
/** Interaction record for updating the graph */
|
|
55
|
+
export interface InteractionRecord {
|
|
56
|
+
from: string;
|
|
57
|
+
to: string;
|
|
58
|
+
scene: string;
|
|
59
|
+
success: boolean;
|
|
60
|
+
task_weight: number;
|
|
61
|
+
duration_ms: number;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Calculate task weight from execution parameters.
|
|
65
|
+
*
|
|
66
|
+
* Formula:
|
|
67
|
+
* task_weight = complexity × value × risk × novelty
|
|
68
|
+
*
|
|
69
|
+
* Where:
|
|
70
|
+
* complexity = min(1, tool_calls × 0.2 + duration_ms / 10000 × 0.3)
|
|
71
|
+
* value = min(1, max_cost / 10)
|
|
72
|
+
* risk = {low:0.5, medium:1.0, high:2.0, critical:3.0}
|
|
73
|
+
* novelty = 1 / (1 + ln(1 + similar_task_count))
|
|
74
|
+
*
|
|
75
|
+
* Example: tool_calls=5, duration_ms=8000, max_cost=5, risk='medium', similar=2
|
|
76
|
+
* complexity = min(1, 5×0.2 + 0.8×0.3) = min(1, 1.24) = 1
|
|
77
|
+
* value = min(1, 0.5) = 0.5
|
|
78
|
+
* risk = 1.0
|
|
79
|
+
* novelty = 1/(1+ln(3)) ≈ 0.476
|
|
80
|
+
* weight = 1 × 0.5 × 1.0 × 0.476 ≈ 0.238
|
|
81
|
+
*/
|
|
82
|
+
export declare function calculateTaskWeight(params: TaskWeightParams): number;
|
|
83
|
+
/**
|
|
84
|
+
* Multi-dimensional trust graph.
|
|
85
|
+
*
|
|
86
|
+
* Nodes = agents, edges = per-scene collaboration records.
|
|
87
|
+
* Supports direct, indirect, and composite trust queries,
|
|
88
|
+
* anomaly detection, and graph export.
|
|
89
|
+
*/
|
|
90
|
+
export declare class TrustGraph {
|
|
91
|
+
private nodes;
|
|
92
|
+
private edges;
|
|
93
|
+
/** Register a new agent node. Idempotent — re-adding updates metadata. */
|
|
94
|
+
addNode(agentId: string, metadata?: Record<string, any>): void;
|
|
95
|
+
getNode(agentId: string): GraphNode | undefined;
|
|
96
|
+
/** Remove a node and all its edges. */
|
|
97
|
+
removeNode(agentId: string): void;
|
|
98
|
+
/**
|
|
99
|
+
* Record a single collaboration interaction.
|
|
100
|
+
* Auto-creates nodes if they don't exist.
|
|
101
|
+
* Updates edge statistics and node interaction counts.
|
|
102
|
+
*
|
|
103
|
+
* Consistency score is maintained as a running exponential moving average
|
|
104
|
+
* of success (1) / failure (0) variance across recent interactions.
|
|
105
|
+
*/
|
|
106
|
+
recordInteraction(interaction: InteractionRecord): void;
|
|
107
|
+
getEdge(from: string, to: string, scene: string): GraphEdge | undefined;
|
|
108
|
+
/** Get all edges involving a given agent (as from or to). */
|
|
109
|
+
getEdges(agentId: string): GraphEdge[];
|
|
110
|
+
/**
|
|
111
|
+
* Direct trust between two agents in a scene.
|
|
112
|
+
*
|
|
113
|
+
* Formula:
|
|
114
|
+
* DirectTrust = swr × recency × consistency × confidence
|
|
115
|
+
*
|
|
116
|
+
* swr = successful_weight / total_weight
|
|
117
|
+
* recency = exp(-0.01 × days_since_last)
|
|
118
|
+
* consistency = edge.consistency_score
|
|
119
|
+
* confidence = min(1, total_tasks / 20)
|
|
120
|
+
*
|
|
121
|
+
* Example: swr=0.8, 10 days ago, consistency=0.9, 15 tasks
|
|
122
|
+
* recency = exp(-0.01×10) ≈ 0.905
|
|
123
|
+
* confidence = min(1, 15/20) = 0.75
|
|
124
|
+
* trust = 0.8 × 0.905 × 0.9 × 0.75 ≈ 0.489
|
|
125
|
+
*
|
|
126
|
+
* Returns trust_score=0 when no edge exists.
|
|
127
|
+
*/
|
|
128
|
+
directTrust(from: string, to: string, scene: string): TrustResult;
|
|
129
|
+
/**
|
|
130
|
+
* Indirect trust via intermediate nodes (BFS, max depth 3).
|
|
131
|
+
*
|
|
132
|
+
* For each path P from A to B:
|
|
133
|
+
* path_trust = ∏(DirectTrust(edge_i)) × 0.7^(|P|-1)
|
|
134
|
+
*
|
|
135
|
+
* Returns the strongest path.
|
|
136
|
+
*
|
|
137
|
+
* Example: A→M trust=0.8, M→B trust=0.7, depth=2
|
|
138
|
+
* path_trust = 0.8 × 0.7 × 0.7^(2-1) = 0.8 × 0.7 × 0.7 = 0.392
|
|
139
|
+
*/
|
|
140
|
+
indirectTrust(from: string, to: string, scene: string, maxDepth?: number): TrustResult;
|
|
141
|
+
/**
|
|
142
|
+
* Composite trust combining direct, indirect, and reputation.
|
|
143
|
+
*
|
|
144
|
+
* CompositeTrust = α×Direct + β×Indirect + γ×ReputationBonus
|
|
145
|
+
* α=0.6, β=0.3, γ=0.1
|
|
146
|
+
*
|
|
147
|
+
* If no direct trust exists, α's weight transfers to β:
|
|
148
|
+
* β_effective = β + α = 0.9
|
|
149
|
+
*
|
|
150
|
+
* ReputationBonus = global_success_rate × 0.5
|
|
151
|
+
*/
|
|
152
|
+
compositeTrust(from: string, to: string, scene: string): TrustResult;
|
|
153
|
+
/** Global success rate across all edges. */
|
|
154
|
+
private _globalSuccessRate;
|
|
155
|
+
/**
|
|
156
|
+
* Scene reputation: average incoming trust for an agent in a scene.
|
|
157
|
+
* Averages directTrust from all agents that have interacted with this agent.
|
|
158
|
+
*/
|
|
159
|
+
sceneReputation(agentId: string, scene: string): number;
|
|
160
|
+
/** Top-K partners by composite trust (across all scenes). */
|
|
161
|
+
topPartners(agentId: string, k: number): Array<{
|
|
162
|
+
agent_id: string;
|
|
163
|
+
trust: number;
|
|
164
|
+
}>;
|
|
165
|
+
/** Top-K agents for a scene by reputation. */
|
|
166
|
+
topAgentsForScene(scene: string, k: number): Array<{
|
|
167
|
+
agent_id: string;
|
|
168
|
+
reputation: number;
|
|
169
|
+
}>;
|
|
170
|
+
/**
|
|
171
|
+
* Strongest trust path from A to B (any depth up to 3).
|
|
172
|
+
* Uses the same BFS as indirectTrust but also considers direct (1-hop).
|
|
173
|
+
*/
|
|
174
|
+
strongestPath(from: string, to: string, scene: string): {
|
|
175
|
+
path: string[];
|
|
176
|
+
trust: number;
|
|
177
|
+
} | null;
|
|
178
|
+
/**
|
|
179
|
+
* Behavior Consistency Score (BCS).
|
|
180
|
+
*
|
|
181
|
+
* BCS = 1 - (max_success_rate - min_success_rate) across all partners.
|
|
182
|
+
* Suspicious if BCS < 0.7 (agent treats different partners very differently).
|
|
183
|
+
*/
|
|
184
|
+
behaviorConsistencyScore(agentId: string): {
|
|
185
|
+
score: number;
|
|
186
|
+
suspicious: boolean;
|
|
187
|
+
details: Record<string, number>;
|
|
188
|
+
};
|
|
189
|
+
/**
|
|
190
|
+
* Detect suspicious clusters (simplified Sybil detection).
|
|
191
|
+
*
|
|
192
|
+
* For each pair of agents, compute internal vs external interaction ratio.
|
|
193
|
+
* Groups with internal_ratio >> external_ratio are suspicious.
|
|
194
|
+
*/
|
|
195
|
+
detectSuspiciousClusters(minClusterSize?: number): Array<{
|
|
196
|
+
agents: string[];
|
|
197
|
+
suspicion_score: number;
|
|
198
|
+
}>;
|
|
199
|
+
/** Generate combinations of size k from array. */
|
|
200
|
+
private _combinations;
|
|
201
|
+
private _rankAgentsByActivity;
|
|
202
|
+
/** Export the full graph as plain objects (Sets converted to arrays). */
|
|
203
|
+
exportGraph(): {
|
|
204
|
+
nodes: GraphNode[];
|
|
205
|
+
edges: GraphEdge[];
|
|
206
|
+
};
|
|
207
|
+
/** Aggregate statistics. */
|
|
208
|
+
getStats(): {
|
|
209
|
+
total_nodes: number;
|
|
210
|
+
total_edges: number;
|
|
211
|
+
total_interactions: number;
|
|
212
|
+
scenes: string[];
|
|
213
|
+
avg_trust: number;
|
|
214
|
+
};
|
|
215
|
+
}
|