kompass-sdk 0.6.0 → 0.8.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.
- package/dist/ranking.d.ts +59 -0
- package/dist/ranking.d.ts.map +1 -0
- package/dist/ranking.js +273 -0
- package/dist/ranking.js.map +1 -0
- package/dist/sources/adp.d.ts +1 -1
- package/dist/sources/adp.d.ts.map +1 -1
- package/dist/sources/adp.js +55 -34
- package/dist/sources/adp.js.map +1 -1
- package/dist/sources/erc8004.d.ts +3 -2
- package/dist/sources/erc8004.d.ts.map +1 -1
- package/dist/sources/erc8004.js +68 -114
- package/dist/sources/erc8004.js.map +1 -1
- package/dist/unified.d.ts +4 -1
- package/dist/unified.d.ts.map +1 -1
- package/dist/unified.js +9 -5
- package/dist/unified.js.map +1 -1
- package/package.json +1 -1
- package/src/ranking.ts +336 -0
- package/src/sources/adp.ts +56 -34
- package/src/sources/erc8004.ts +60 -121
- package/src/unified.ts +13 -6
- package/test-ranking.ts +53 -0
package/src/unified.ts
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
import { createAllSources, type SourceAdapter, type UnifiedAgent } from "./sources/index.js";
|
|
14
14
|
import { Aggregator, type AggregatorOptions, type AggregatorResult } from "./aggregator.js";
|
|
15
15
|
import { rankAgents, type MatchResult } from "./matching.js";
|
|
16
|
+
import { rankAgentsV2, type RankedAgent } from "./ranking.js";
|
|
16
17
|
import { ProtocolBridge, type BridgeHireOptions, type BridgeHireResult } from "./bridge.js";
|
|
17
18
|
import { CapabilityRouter, type DoOptions, type DoResult } from "./router.js";
|
|
18
19
|
import type { ReputationWriterConfig } from "./reputation-writer.js";
|
|
@@ -44,8 +45,10 @@ export interface FindOptions {
|
|
|
44
45
|
}
|
|
45
46
|
|
|
46
47
|
export interface FindResult extends AggregatorResult {
|
|
47
|
-
/** Agents re-ranked by multi-layer matching */
|
|
48
|
+
/** Agents re-ranked by multi-layer matching (v1) */
|
|
48
49
|
ranked: MatchResult[];
|
|
50
|
+
/** Agents re-ranked by v2 engine (Bayesian + geometric + value) */
|
|
51
|
+
rankedV2?: RankedAgent[];
|
|
49
52
|
}
|
|
50
53
|
|
|
51
54
|
export class KompassUnified {
|
|
@@ -89,18 +92,22 @@ export class KompassUnified {
|
|
|
89
92
|
timeout: options?.timeout,
|
|
90
93
|
});
|
|
91
94
|
|
|
92
|
-
// Re-rank with
|
|
95
|
+
// Re-rank with v2 ranking engine (Bayesian + geometric + value-for-money)
|
|
96
|
+
const rankedV2 = rankAgentsV2(aggregatorResult.agents, query);
|
|
97
|
+
|
|
98
|
+
// Also keep v1 for backward compat
|
|
93
99
|
const ranked = rankAgents(aggregatorResult.agents, query);
|
|
94
100
|
|
|
95
|
-
// Apply limit and min score
|
|
101
|
+
// Apply limit and min score using v2 composite
|
|
96
102
|
const filtered = options?.minScore
|
|
97
|
-
?
|
|
98
|
-
:
|
|
103
|
+
? rankedV2.filter((r) => r.scores.composite >= options.minScore!)
|
|
104
|
+
: rankedV2;
|
|
99
105
|
|
|
100
106
|
return {
|
|
101
107
|
...aggregatorResult,
|
|
102
108
|
agents: filtered.slice(0, options?.limit ?? 20).map((r) => r.agent),
|
|
103
|
-
ranked:
|
|
109
|
+
ranked: ranked.slice(0, options?.limit ?? 20), // v1 for backward compat
|
|
110
|
+
rankedV2: filtered.slice(0, options?.limit ?? 20), // v2 with proper scoring
|
|
104
111
|
};
|
|
105
112
|
}
|
|
106
113
|
|
package/test-ranking.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { KompassUnified } from './src/unified.js';
|
|
2
|
+
|
|
3
|
+
async function main() {
|
|
4
|
+
const kompass = await KompassUnified.create();
|
|
5
|
+
const result = await kompass.find('DeFi yield data', { limit: 20 });
|
|
6
|
+
|
|
7
|
+
console.log('=== SOURCES ===');
|
|
8
|
+
for (const s of result.sources) {
|
|
9
|
+
console.log(` ${s.name}: ${s.count} agents (${s.durationMs}ms)${s.error ? ' ERROR: '+s.error : ''}`);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
console.log(`\nTotal: ${result.totalFound} found, ${result.deduplicated} deduped, ${result.queryTimeMs}ms`);
|
|
13
|
+
|
|
14
|
+
const bySrc: Record<string, number> = {};
|
|
15
|
+
const byProto: Record<string, number> = {};
|
|
16
|
+
for (const a of result.agents) {
|
|
17
|
+
bySrc[a.source] = (bySrc[a.source] || 0) + 1;
|
|
18
|
+
byProto[a.protocol] = (byProto[a.protocol] || 0) + 1;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
console.log('\n=== BY SOURCE ===');
|
|
22
|
+
for (const [k, v] of Object.entries(bySrc).sort((a, b) => b[1] - a[1])) console.log(` ${k}: ${v}`);
|
|
23
|
+
|
|
24
|
+
console.log('\n=== BY PROTOCOL ===');
|
|
25
|
+
for (const [k, v] of Object.entries(byProto).sort((a, b) => b[1] - a[1])) console.log(` ${k}: ${v}`);
|
|
26
|
+
|
|
27
|
+
console.log('\n=== V2 RANKING (Bayesian + Geometric + Value-for-Money) ===');
|
|
28
|
+
console.log(' # Proto Name Source Cost Composite Relevance Quality Volume Value Explanation');
|
|
29
|
+
console.log(' ' + '─'.repeat(170));
|
|
30
|
+
|
|
31
|
+
const v2 = result.rankedV2 ?? [];
|
|
32
|
+
for (let i = 0; i < Math.min(20, v2.length); i++) {
|
|
33
|
+
const r = v2[i];
|
|
34
|
+
const a = r.agent;
|
|
35
|
+
const s = r.scores;
|
|
36
|
+
const proto = a.protocol.toUpperCase().padEnd(6);
|
|
37
|
+
const name = (a.name ?? '?').slice(0, 35).padEnd(35);
|
|
38
|
+
const src = a.source.padEnd(18);
|
|
39
|
+
const price = a.pricing?.amount ? `$${a.pricing.amount}` : 'free/?';
|
|
40
|
+
|
|
41
|
+
console.log(
|
|
42
|
+
` ${String(i + 1).padStart(2)} [${proto}] ${name} | ${src} | ${price.padEnd(10)} | ` +
|
|
43
|
+
`comp=${s.composite.toFixed(1).padEnd(6)} | ` +
|
|
44
|
+
`rel=${s.relevance.toFixed(0).padEnd(4)} | ` +
|
|
45
|
+
`qual=${s.quality.toFixed(1).padEnd(6)} | ` +
|
|
46
|
+
`vol=${s.volume.toFixed(0).padEnd(4)} | ` +
|
|
47
|
+
`val=${s.value.toFixed(1).padEnd(6)} | ` +
|
|
48
|
+
`${r.explanation}`
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
main().catch(console.error);
|