kompass-sdk 0.19.0 → 0.20.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/matching.d.ts +1 -1
- package/dist/matching.d.ts.map +1 -1
- package/dist/matching.js +67 -14
- package/dist/matching.js.map +1 -1
- package/package.json +1 -1
- package/src/matching.ts +64 -14
package/dist/matching.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Layer A: Structured capability matching (ontology-style)
|
|
5
5
|
* Layer B: BM25 text relevance scoring
|
|
6
6
|
* Layer C: LLM re-ranking (optional, for top candidates)
|
|
7
|
-
* Layer D: Multi-criteria scoring (reputation, price, protocol, recency)
|
|
7
|
+
* Layer D: Multi-criteria scoring (reputation, price, protocol, recency, liveness)
|
|
8
8
|
*/
|
|
9
9
|
import type { UnifiedAgent } from "./sources/types.js";
|
|
10
10
|
interface ParsedIntent {
|
package/dist/matching.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"matching.d.ts","sourceRoot":"","sources":["../src/matching.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAIvD,UAAU,YAAY;IACpB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB;
|
|
1
|
+
{"version":3,"file":"matching.d.ts","sourceRoot":"","sources":["../src/matching.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAIvD,UAAU,YAAY;IACpB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB;AAgCD,iBAAS,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,YAAY,CA0BhD;AAgJD,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,YAAY,CAAC;IACpB,MAAM,EAAE;QACN,UAAU,EAAE,MAAM,CAAC;QACnB,IAAI,EAAE,MAAM,CAAC;QACb,aAAa,EAAE,MAAM,CAAC;QACtB,KAAK,EAAE,MAAM,CAAC;KACf,CAAC;CACH;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,WAAW,EAAE,CAiB/E;AAED,OAAO,EAAE,WAAW,EAAE,KAAK,YAAY,EAAE,CAAC"}
|
package/dist/matching.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Layer A: Structured capability matching (ontology-style)
|
|
5
5
|
* Layer B: BM25 text relevance scoring
|
|
6
6
|
* Layer C: LLM re-ranking (optional, for top candidates)
|
|
7
|
-
* Layer D: Multi-criteria scoring (reputation, price, protocol, recency)
|
|
7
|
+
* Layer D: Multi-criteria scoring (reputation, price, protocol, recency, liveness)
|
|
8
8
|
*/
|
|
9
9
|
const DOMAIN_KEYWORDS = {
|
|
10
10
|
defi: ["defi", "yield", "swap", "liquidity", "pool", "lending", "borrow", "stake", "vault", "farm"],
|
|
@@ -15,6 +15,8 @@ const DOMAIN_KEYWORDS = {
|
|
|
15
15
|
development: ["code", "develop", "build", "deploy", "smart contract", "solidity"],
|
|
16
16
|
ai: ["ai", "llm", "model", "inference", "embedding", "prompt"],
|
|
17
17
|
social: ["social", "twitter", "post", "tweet", "farcaster"],
|
|
18
|
+
scraping: ["scrape", "crawl", "extract", "web scraping", "firecrawl"],
|
|
19
|
+
crypto: ["crypto", "bitcoin", "ethereum", "eth", "btc", "sol", "token", "coin", "wallet", "chain", "gas"],
|
|
18
20
|
};
|
|
19
21
|
const PROTOCOL_KEYWORDS = {
|
|
20
22
|
x402: ["x402", "micropayment", "http 402", "pay per call"],
|
|
@@ -74,7 +76,7 @@ function structuredScore(agent, intent) {
|
|
|
74
76
|
if (price <= intent.priceMax)
|
|
75
77
|
score += 10;
|
|
76
78
|
else
|
|
77
|
-
score -= 10;
|
|
79
|
+
score -= 10;
|
|
78
80
|
}
|
|
79
81
|
return score;
|
|
80
82
|
}
|
|
@@ -83,46 +85,94 @@ function bm25Score(agent, queryTerms) {
|
|
|
83
85
|
const doc = `${agent.name} ${agent.description} ${agent.categories.join(" ")} ${agent.capabilities.join(" ")}`.toLowerCase();
|
|
84
86
|
const docTerms = doc.split(/\s+/);
|
|
85
87
|
const docLen = docTerms.length;
|
|
86
|
-
const avgDocLen = 50;
|
|
88
|
+
const avgDocLen = 50;
|
|
87
89
|
const k1 = 1.5;
|
|
88
90
|
const b = 0.75;
|
|
89
91
|
let score = 0;
|
|
92
|
+
let matchedTerms = 0;
|
|
90
93
|
for (const term of queryTerms) {
|
|
91
94
|
const tf = docTerms.filter((t) => t.includes(term)).length;
|
|
92
95
|
if (tf === 0)
|
|
93
96
|
continue;
|
|
97
|
+
matchedTerms++;
|
|
94
98
|
// Simplified BM25
|
|
95
99
|
const numerator = tf * (k1 + 1);
|
|
96
100
|
const denominator = tf + k1 * (1 - b + b * (docLen / avgDocLen));
|
|
97
101
|
score += numerator / denominator;
|
|
98
102
|
}
|
|
99
|
-
|
|
103
|
+
// Bonus for matching ALL query terms (full relevance)
|
|
104
|
+
if (queryTerms.length > 0 && matchedTerms === queryTerms.length) {
|
|
105
|
+
score *= 1.5;
|
|
106
|
+
}
|
|
107
|
+
// Penalty for very long descriptions that match generically
|
|
108
|
+
// Short, focused descriptions that match = better than long generic ones
|
|
109
|
+
if (docLen > 100) {
|
|
110
|
+
score *= 0.8; // 20% penalty for bloated descriptions
|
|
111
|
+
}
|
|
112
|
+
return score * 10;
|
|
100
113
|
}
|
|
101
114
|
// ── Layer D: Multi-Criteria Scoring ──────────────────────
|
|
102
115
|
function multiCriteriaScore(agent) {
|
|
103
116
|
let score = 0;
|
|
104
|
-
// Reputation
|
|
117
|
+
// Reputation — agents with real track record get boosted
|
|
105
118
|
if (agent.reputation) {
|
|
106
119
|
score += Math.min(agent.reputation.score * 0.2, 20);
|
|
107
120
|
score += Math.min(agent.reputation.count * 0.5, 10);
|
|
108
121
|
}
|
|
122
|
+
else {
|
|
123
|
+
// No reputation = untested = slight penalty
|
|
124
|
+
score -= 3;
|
|
125
|
+
}
|
|
109
126
|
// Verified identity
|
|
110
127
|
if (agent.verified)
|
|
111
128
|
score += 5;
|
|
112
129
|
// Pricing transparency
|
|
113
130
|
if (agent.pricing && agent.pricing.model !== "unknown")
|
|
114
131
|
score += 3;
|
|
115
|
-
//
|
|
116
|
-
const
|
|
132
|
+
// Liveness: agents with callable endpoints that we KNOW work
|
|
133
|
+
const hasHttp = !!agent.endpoints.http;
|
|
134
|
+
const hasMcp = !!agent.endpoints.mcp;
|
|
135
|
+
const hasX402 = !!agent.endpoints.x402;
|
|
136
|
+
const hasAcp = !!agent.endpoints.acp;
|
|
137
|
+
const endpointCount = [hasHttp, hasMcp, hasX402, hasAcp, !!agent.endpoints.a2a, !!agent.endpoints.l402].filter(Boolean).length;
|
|
117
138
|
score += endpointCount * 2;
|
|
118
|
-
//
|
|
119
|
-
//
|
|
120
|
-
|
|
121
|
-
|
|
139
|
+
// Source-specific liveness signals
|
|
140
|
+
// Agents from sources we KNOW are live gateways (not just registrations)
|
|
141
|
+
switch (agent.source) {
|
|
142
|
+
case "bankr":
|
|
143
|
+
score += 15; // Bankr is a live gateway, always responds
|
|
144
|
+
break;
|
|
145
|
+
case "locus":
|
|
146
|
+
score += 12; // Locus wrapped APIs are live
|
|
147
|
+
break;
|
|
148
|
+
case "x402-ecosystem":
|
|
149
|
+
score += 10; // 402index verifies health
|
|
150
|
+
break;
|
|
151
|
+
case "acp":
|
|
152
|
+
score += 8; // ACP agents are registered and active
|
|
153
|
+
break;
|
|
154
|
+
case "olas":
|
|
155
|
+
score += 8; // Olas mechs have on-chain delivery records
|
|
156
|
+
break;
|
|
157
|
+
case "mcp-registry":
|
|
158
|
+
// Only boost if it has a remote endpoint — many MCP servers are local-only
|
|
159
|
+
if (hasMcp)
|
|
160
|
+
score += 5;
|
|
161
|
+
else
|
|
162
|
+
score -= 5; // Penalize MCP without remote endpoint
|
|
163
|
+
break;
|
|
164
|
+
case "erc8004":
|
|
165
|
+
// ERC-8004 is a registry — agents may or may not be live
|
|
166
|
+
// Only boost if they have a callable endpoint
|
|
167
|
+
if (hasHttp || hasMcp || hasX402)
|
|
168
|
+
score += 3;
|
|
169
|
+
else
|
|
170
|
+
score -= 5; // Paper registration, no live endpoint
|
|
171
|
+
break;
|
|
172
|
+
case "skills-registry":
|
|
173
|
+
score -= 10; // Skills aren't hirable — heavy penalty if they slip through
|
|
174
|
+
break;
|
|
122
175
|
}
|
|
123
|
-
// Free tools get a small accessibility bonus (no wallet needed)
|
|
124
|
-
if (agent.pricing?.model === "free")
|
|
125
|
-
score += 3;
|
|
126
176
|
// Recency
|
|
127
177
|
if (agent.lastSeen) {
|
|
128
178
|
const hoursSince = (Date.now() - agent.lastSeen) / (1000 * 60 * 60);
|
|
@@ -133,6 +183,9 @@ function multiCriteriaScore(agent) {
|
|
|
133
183
|
else if (hoursSince < 168)
|
|
134
184
|
score += 1;
|
|
135
185
|
}
|
|
186
|
+
// Free tools get a small accessibility bonus
|
|
187
|
+
if (agent.pricing?.model === "free")
|
|
188
|
+
score += 2;
|
|
136
189
|
return score;
|
|
137
190
|
}
|
|
138
191
|
export function rankAgents(agents, query) {
|
package/dist/matching.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"matching.js","sourceRoot":"","sources":["../src/matching.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAcH,MAAM,eAAe,GAA6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ACb,MAAM,UAAU,GAAG,eAAe,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QAClD,MAAM,IAAI,GAAG,SAAS,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;QAC1C,MAAM,KAAK,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAC;QACxC,MAAM,KAAK,GAAG,UAAU,GAAG,IAAI,GAAG,KAAK,CAAC;QAExC,OAAO;YACL,KAAK;YACL,MAAM,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,KAAK,EAAE;SAC1D,CAAC;IACJ,CAAC,CAAC;SACD,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACrD,CAAC;AAED,OAAO,EAAE,WAAW,EAAqB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kompass-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.0",
|
|
4
4
|
"description": "Get any job done. Universal agent capability discovery + coordination across ACP, MCP, x402, A2A, skills, L402, and ERC-8004.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
package/src/matching.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Layer A: Structured capability matching (ontology-style)
|
|
5
5
|
* Layer B: BM25 text relevance scoring
|
|
6
6
|
* Layer C: LLM re-ranking (optional, for top candidates)
|
|
7
|
-
* Layer D: Multi-criteria scoring (reputation, price, protocol, recency)
|
|
7
|
+
* Layer D: Multi-criteria scoring (reputation, price, protocol, recency, liveness)
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import type { UnifiedAgent } from "./sources/types.js";
|
|
@@ -28,6 +28,8 @@ const DOMAIN_KEYWORDS: Record<string, string[]> = {
|
|
|
28
28
|
development: ["code", "develop", "build", "deploy", "smart contract", "solidity"],
|
|
29
29
|
ai: ["ai", "llm", "model", "inference", "embedding", "prompt"],
|
|
30
30
|
social: ["social", "twitter", "post", "tweet", "farcaster"],
|
|
31
|
+
scraping: ["scrape", "crawl", "extract", "web scraping", "firecrawl"],
|
|
32
|
+
crypto: ["crypto", "bitcoin", "ethereum", "eth", "btc", "sol", "token", "coin", "wallet", "chain", "gas"],
|
|
31
33
|
};
|
|
32
34
|
|
|
33
35
|
const PROTOCOL_KEYWORDS: Record<string, string[]> = {
|
|
@@ -96,7 +98,7 @@ function structuredScore(agent: UnifiedAgent, intent: ParsedIntent): number {
|
|
|
96
98
|
if (intent.priceMax && agent.pricing?.amount) {
|
|
97
99
|
const price = parseFloat(agent.pricing.amount);
|
|
98
100
|
if (price <= intent.priceMax) score += 10;
|
|
99
|
-
else score -= 10;
|
|
101
|
+
else score -= 10;
|
|
100
102
|
}
|
|
101
103
|
|
|
102
104
|
return score;
|
|
@@ -108,14 +110,16 @@ function bm25Score(agent: UnifiedAgent, queryTerms: string[]): number {
|
|
|
108
110
|
const doc = `${agent.name} ${agent.description} ${agent.categories.join(" ")} ${agent.capabilities.join(" ")}`.toLowerCase();
|
|
109
111
|
const docTerms = doc.split(/\s+/);
|
|
110
112
|
const docLen = docTerms.length;
|
|
111
|
-
const avgDocLen = 50;
|
|
113
|
+
const avgDocLen = 50;
|
|
112
114
|
const k1 = 1.5;
|
|
113
115
|
const b = 0.75;
|
|
114
116
|
|
|
115
117
|
let score = 0;
|
|
118
|
+
let matchedTerms = 0;
|
|
116
119
|
for (const term of queryTerms) {
|
|
117
120
|
const tf = docTerms.filter((t) => t.includes(term)).length;
|
|
118
121
|
if (tf === 0) continue;
|
|
122
|
+
matchedTerms++;
|
|
119
123
|
|
|
120
124
|
// Simplified BM25
|
|
121
125
|
const numerator = tf * (k1 + 1);
|
|
@@ -123,7 +127,18 @@ function bm25Score(agent: UnifiedAgent, queryTerms: string[]): number {
|
|
|
123
127
|
score += numerator / denominator;
|
|
124
128
|
}
|
|
125
129
|
|
|
126
|
-
|
|
130
|
+
// Bonus for matching ALL query terms (full relevance)
|
|
131
|
+
if (queryTerms.length > 0 && matchedTerms === queryTerms.length) {
|
|
132
|
+
score *= 1.5;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Penalty for very long descriptions that match generically
|
|
136
|
+
// Short, focused descriptions that match = better than long generic ones
|
|
137
|
+
if (docLen > 100) {
|
|
138
|
+
score *= 0.8; // 20% penalty for bloated descriptions
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return score * 10;
|
|
127
142
|
}
|
|
128
143
|
|
|
129
144
|
// ── Layer D: Multi-Criteria Scoring ──────────────────────
|
|
@@ -131,10 +146,13 @@ function bm25Score(agent: UnifiedAgent, queryTerms: string[]): number {
|
|
|
131
146
|
function multiCriteriaScore(agent: UnifiedAgent): number {
|
|
132
147
|
let score = 0;
|
|
133
148
|
|
|
134
|
-
// Reputation
|
|
149
|
+
// Reputation — agents with real track record get boosted
|
|
135
150
|
if (agent.reputation) {
|
|
136
151
|
score += Math.min(agent.reputation.score * 0.2, 20);
|
|
137
152
|
score += Math.min(agent.reputation.count * 0.5, 10);
|
|
153
|
+
} else {
|
|
154
|
+
// No reputation = untested = slight penalty
|
|
155
|
+
score -= 3;
|
|
138
156
|
}
|
|
139
157
|
|
|
140
158
|
// Verified identity
|
|
@@ -143,19 +161,48 @@ function multiCriteriaScore(agent: UnifiedAgent): number {
|
|
|
143
161
|
// Pricing transparency
|
|
144
162
|
if (agent.pricing && agent.pricing.model !== "unknown") score += 3;
|
|
145
163
|
|
|
146
|
-
//
|
|
147
|
-
const
|
|
164
|
+
// Liveness: agents with callable endpoints that we KNOW work
|
|
165
|
+
const hasHttp = !!agent.endpoints.http;
|
|
166
|
+
const hasMcp = !!agent.endpoints.mcp;
|
|
167
|
+
const hasX402 = !!agent.endpoints.x402;
|
|
168
|
+
const hasAcp = !!agent.endpoints.acp;
|
|
169
|
+
const endpointCount = [hasHttp, hasMcp, hasX402, hasAcp, !!agent.endpoints.a2a, !!agent.endpoints.l402].filter(Boolean).length;
|
|
148
170
|
score += endpointCount * 2;
|
|
149
171
|
|
|
150
|
-
//
|
|
151
|
-
//
|
|
152
|
-
|
|
153
|
-
|
|
172
|
+
// Source-specific liveness signals
|
|
173
|
+
// Agents from sources we KNOW are live gateways (not just registrations)
|
|
174
|
+
switch (agent.source as string) {
|
|
175
|
+
case "bankr":
|
|
176
|
+
score += 15; // Bankr is a live gateway, always responds
|
|
177
|
+
break;
|
|
178
|
+
case "locus":
|
|
179
|
+
score += 12; // Locus wrapped APIs are live
|
|
180
|
+
break;
|
|
181
|
+
case "x402-ecosystem":
|
|
182
|
+
score += 10; // 402index verifies health
|
|
183
|
+
break;
|
|
184
|
+
case "acp":
|
|
185
|
+
score += 8; // ACP agents are registered and active
|
|
186
|
+
break;
|
|
187
|
+
case "olas":
|
|
188
|
+
score += 8; // Olas mechs have on-chain delivery records
|
|
189
|
+
break;
|
|
190
|
+
case "mcp-registry":
|
|
191
|
+
// Only boost if it has a remote endpoint — many MCP servers are local-only
|
|
192
|
+
if (hasMcp) score += 5;
|
|
193
|
+
else score -= 5; // Penalize MCP without remote endpoint
|
|
194
|
+
break;
|
|
195
|
+
case "erc8004":
|
|
196
|
+
// ERC-8004 is a registry — agents may or may not be live
|
|
197
|
+
// Only boost if they have a callable endpoint
|
|
198
|
+
if (hasHttp || hasMcp || hasX402) score += 3;
|
|
199
|
+
else score -= 5; // Paper registration, no live endpoint
|
|
200
|
+
break;
|
|
201
|
+
case "skills-registry":
|
|
202
|
+
score -= 10; // Skills aren't hirable — heavy penalty if they slip through
|
|
203
|
+
break;
|
|
154
204
|
}
|
|
155
205
|
|
|
156
|
-
// Free tools get a small accessibility bonus (no wallet needed)
|
|
157
|
-
if (agent.pricing?.model === "free") score += 3;
|
|
158
|
-
|
|
159
206
|
// Recency
|
|
160
207
|
if (agent.lastSeen) {
|
|
161
208
|
const hoursSince = (Date.now() - agent.lastSeen) / (1000 * 60 * 60);
|
|
@@ -164,6 +211,9 @@ function multiCriteriaScore(agent: UnifiedAgent): number {
|
|
|
164
211
|
else if (hoursSince < 168) score += 1;
|
|
165
212
|
}
|
|
166
213
|
|
|
214
|
+
// Free tools get a small accessibility bonus
|
|
215
|
+
if (agent.pricing?.model === "free") score += 2;
|
|
216
|
+
|
|
167
217
|
return score;
|
|
168
218
|
}
|
|
169
219
|
|