@rookdaemon/agora 0.3.0 → 0.4.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.
|
@@ -1550,7 +1550,7 @@ function verdictWeight(verdict) {
|
|
|
1550
1550
|
return 0;
|
|
1551
1551
|
}
|
|
1552
1552
|
}
|
|
1553
|
-
function computeTrustScore(agent, domain, verifications, currentTime) {
|
|
1553
|
+
function computeTrustScore(agent, domain, verifications, currentTime, options) {
|
|
1554
1554
|
const relevantVerifications = verifications.filter(
|
|
1555
1555
|
(v) => v.target === agent && v.domain === domain
|
|
1556
1556
|
);
|
|
@@ -1564,17 +1564,34 @@ function computeTrustScore(agent, domain, verifications, currentTime) {
|
|
|
1564
1564
|
topVerifiers: []
|
|
1565
1565
|
};
|
|
1566
1566
|
}
|
|
1567
|
+
const maxDepth = options?.maxDepth ?? 3;
|
|
1568
|
+
const visitedAgents = options?.visitedAgents;
|
|
1569
|
+
const getVerifierScore = options?.getVerifierScore;
|
|
1570
|
+
if (visitedAgents) {
|
|
1571
|
+
visitedAgents.add(agent);
|
|
1572
|
+
}
|
|
1567
1573
|
let totalWeight = 0;
|
|
1568
1574
|
const verifierWeights = /* @__PURE__ */ new Map();
|
|
1569
1575
|
for (const verification of relevantVerifications) {
|
|
1570
1576
|
const deltaTime = currentTime - verification.timestamp;
|
|
1571
1577
|
const decayFactor = decay(deltaTime);
|
|
1572
1578
|
const verdict = verdictWeight(verification.verdict);
|
|
1573
|
-
|
|
1579
|
+
let verifierTrustWeight;
|
|
1580
|
+
if (!getVerifierScore || maxDepth <= 0) {
|
|
1581
|
+
verifierTrustWeight = 1;
|
|
1582
|
+
} else if (visitedAgents?.has(verification.verifier)) {
|
|
1583
|
+
verifierTrustWeight = 0.5;
|
|
1584
|
+
} else {
|
|
1585
|
+
verifierTrustWeight = getVerifierScore(verification.verifier, domain);
|
|
1586
|
+
}
|
|
1587
|
+
const weight = verdict * verification.confidence * decayFactor * verifierTrustWeight;
|
|
1574
1588
|
totalWeight += weight;
|
|
1575
|
-
const currentVerifierWeight = verifierWeights.get(verification.verifier)
|
|
1589
|
+
const currentVerifierWeight = verifierWeights.get(verification.verifier) ?? 0;
|
|
1576
1590
|
verifierWeights.set(verification.verifier, currentVerifierWeight + Math.abs(weight));
|
|
1577
1591
|
}
|
|
1592
|
+
if (visitedAgents) {
|
|
1593
|
+
visitedAgents.delete(agent);
|
|
1594
|
+
}
|
|
1578
1595
|
const rawScore = totalWeight / Math.max(relevantVerifications.length, 1);
|
|
1579
1596
|
const normalizedScore = Math.max(0, Math.min(1, (rawScore + 1) / 2));
|
|
1580
1597
|
const lastVerified = Math.max(...relevantVerifications.map((v) => v.timestamp));
|
|
@@ -1642,4 +1659,4 @@ export {
|
|
|
1642
1659
|
computeTrustScores,
|
|
1643
1660
|
computeAllTrustScores
|
|
1644
1661
|
};
|
|
1645
|
-
//# sourceMappingURL=chunk-
|
|
1662
|
+
//# sourceMappingURL=chunk-7RX2YC4A.js.map
|