kompass-sdk 0.20.0 → 0.21.1

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.
Files changed (84) hide show
  1. package/dist/aggregator.d.ts.map +1 -1
  2. package/dist/aggregator.js +13 -6
  3. package/dist/aggregator.js.map +1 -1
  4. package/dist/basename.d.ts +59 -0
  5. package/dist/basename.d.ts.map +1 -0
  6. package/dist/basename.js +253 -0
  7. package/dist/basename.js.map +1 -0
  8. package/dist/bridge.d.ts.map +1 -1
  9. package/dist/bridge.js +64 -0
  10. package/dist/bridge.js.map +1 -1
  11. package/dist/cli.js +101 -0
  12. package/dist/cli.js.map +1 -1
  13. package/dist/erc8004.d.ts +179 -0
  14. package/dist/erc8004.d.ts.map +1 -0
  15. package/dist/erc8004.js +187 -0
  16. package/dist/erc8004.js.map +1 -0
  17. package/dist/index.d.ts +6 -0
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +6 -0
  20. package/dist/index.js.map +1 -1
  21. package/dist/matching.d.ts.map +1 -1
  22. package/dist/matching.js +7 -6
  23. package/dist/matching.js.map +1 -1
  24. package/dist/onboard.d.ts +132 -0
  25. package/dist/onboard.d.ts.map +1 -0
  26. package/dist/onboard.js +285 -0
  27. package/dist/onboard.js.map +1 -0
  28. package/dist/router.js +2 -2
  29. package/dist/router.js.map +1 -1
  30. package/dist/sources/acp.d.ts.map +1 -1
  31. package/dist/sources/acp.js +8 -7
  32. package/dist/sources/acp.js.map +1 -1
  33. package/dist/sources/bankr.d.ts.map +1 -1
  34. package/dist/sources/bankr.js +7 -4
  35. package/dist/sources/bankr.js.map +1 -1
  36. package/dist/sources/erc8004.js +2 -2
  37. package/dist/sources/erc8004.js.map +1 -1
  38. package/dist/sources/locus.d.ts.map +1 -1
  39. package/dist/sources/locus.js +4 -0
  40. package/dist/sources/locus.js.map +1 -1
  41. package/dist/sources/mcp-registry.d.ts.map +1 -1
  42. package/dist/sources/mcp-registry.js +6 -0
  43. package/dist/sources/mcp-registry.js.map +1 -1
  44. package/dist/sources/olas.d.ts +3 -3
  45. package/dist/sources/olas.d.ts.map +1 -1
  46. package/dist/sources/olas.js +37 -31
  47. package/dist/sources/olas.js.map +1 -1
  48. package/dist/sources/skills.d.ts.map +1 -1
  49. package/dist/sources/skills.js +4 -2
  50. package/dist/sources/skills.js.map +1 -1
  51. package/dist/sources/x402-ecosystem.js +1 -1
  52. package/dist/sources/x402-ecosystem.js.map +1 -1
  53. package/dist/wallet/handlers/bankr.d.ts.map +1 -1
  54. package/dist/wallet/handlers/bankr.js +5 -4
  55. package/dist/wallet/handlers/bankr.js.map +1 -1
  56. package/dist/wallet/handlers/locus.d.ts.map +1 -1
  57. package/dist/wallet/handlers/locus.js +3 -2
  58. package/dist/wallet/handlers/locus.js.map +1 -1
  59. package/dist/wallet/handlers/olas.d.ts +5 -1
  60. package/dist/wallet/handlers/olas.d.ts.map +1 -1
  61. package/dist/wallet/handlers/olas.js +20 -28
  62. package/dist/wallet/handlers/olas.js.map +1 -1
  63. package/dist/wallet/index.d.ts +20 -20
  64. package/package.json +1 -1
  65. package/src/aggregator.ts +8 -4
  66. package/src/basename.ts +334 -0
  67. package/src/bridge.ts +53 -0
  68. package/src/cli.ts +113 -0
  69. package/src/erc8004.ts +253 -0
  70. package/src/index.ts +12 -0
  71. package/src/matching.ts +7 -6
  72. package/src/onboard.ts +420 -0
  73. package/src/router.ts +2 -2
  74. package/src/sources/acp.ts +8 -7
  75. package/src/sources/bankr.ts +6 -4
  76. package/src/sources/erc8004.ts +2 -2
  77. package/src/sources/locus.ts +5 -0
  78. package/src/sources/mcp-registry.ts +6 -0
  79. package/src/sources/olas.ts +53 -44
  80. package/src/sources/skills.ts +5 -2
  81. package/src/sources/x402-ecosystem.ts +1 -1
  82. package/src/wallet/handlers/bankr.ts +6 -4
  83. package/src/wallet/handlers/locus.ts +3 -2
  84. package/src/wallet/handlers/olas.ts +25 -30
package/src/cli.ts CHANGED
@@ -525,6 +525,119 @@ program
525
525
  console.log(`\n${online}/${health.length} sources online\n`);
526
526
  });
527
527
 
528
+ // ── Onboard Command ─────────────────────────────────────
529
+
530
+ program
531
+ .command("onboard")
532
+ .description("Onboard a new agent: wallet + ERC-8004 identity + Basename + ENS records")
533
+ .requiredOption("--name <name>", "Agent name (used for Basename, e.g. 'my-agent')")
534
+ .requiredOption("--description <desc>", "What this agent does")
535
+ .option("--categories <cats>", "Comma-separated categories", "general")
536
+ .option("--capabilities <caps>", "Comma-separated capabilities", "")
537
+ .option("--agent-type <type>", "provider | evaluator | both", "provider")
538
+ .option("--endpoint-mcp <url>", "MCP endpoint URL")
539
+ .option("--endpoint-x402 <url>", "x402 endpoint URL")
540
+ .option("--endpoint-http <url>", "HTTP endpoint URL")
541
+ .option("--pricing-model <model>", "escrow | x402 | free", "free")
542
+ .option("--pricing-rate <rate>", "Price per task in USDC")
543
+ .option("-n, --network <network>", "base or base-sepolia", "base")
544
+ .option("-w, --wallet <path>", "Existing wallet keystore path")
545
+ .option("--skip-basename", "Skip Basename registration")
546
+ .option("--skip-registry", "Skip Kompass Registry registration")
547
+ .option("--json", "Output as JSON")
548
+ .action(async (opts: any) => {
549
+ const { initOnboarding, completeOnboarding } = await import("./onboard.js");
550
+ const { KompassWallet } = await import("./wallet/index.js");
551
+
552
+ const options = {
553
+ name: opts.name,
554
+ description: opts.description,
555
+ categories: opts.categories.split(",").map((c: string) => c.trim()),
556
+ capabilities: opts.capabilities ? opts.capabilities.split(",").map((c: string) => c.trim()) : [],
557
+ agentType: opts.agentType as "provider" | "evaluator" | "both",
558
+ endpoints: {
559
+ mcp: opts.endpointMcp,
560
+ x402: opts.endpointX402,
561
+ http: opts.endpointHttp,
562
+ },
563
+ pricingModel: opts.pricingModel as "escrow" | "x402" | "free",
564
+ pricingRate: opts.pricingRate,
565
+ network: opts.network as "base" | "base-sepolia",
566
+ walletPath: opts.wallet,
567
+ skipBasename: opts.skipBasename,
568
+ skipKompassRegistry: opts.skipRegistry,
569
+ };
570
+
571
+ // Step 1: Initialize
572
+ if (!opts.json) console.log(`\n⚡ Kompass Agent Onboarding\n`);
573
+
574
+ const init = initOnboarding(options);
575
+
576
+ if (!opts.json) {
577
+ console.log(` Wallet: ${init.walletAddress}`);
578
+ console.log(` Network: ${init.network}`);
579
+ console.log(` Estimated cost: ${init.estimatedCosts.total}`);
580
+ console.log(`\n Fund this wallet with ETH before proceeding.`);
581
+ }
582
+
583
+ // Step 2: Poll for funding
584
+ if (!opts.json) console.log(`\n Checking balance...`);
585
+
586
+ const wallet = KompassWallet.load(
587
+ options.walletPath ?? `${process.env.HOME}/.kompass/wallet.json`,
588
+ undefined,
589
+ );
590
+
591
+ const balance = await wallet.getBalance();
592
+
593
+ if (balance.ethRaw < 500000000000000n) {
594
+ if (opts.json) {
595
+ console.log(JSON.stringify({ status: "awaiting_funding", ...init }));
596
+ } else {
597
+ console.log(` ETH balance: ${balance.eth}`);
598
+ console.log(`\n ⚠ Insufficient funds. Send at least ${init.fundingRequired.eth} ETH to:`);
599
+ console.log(` ${init.walletAddress}`);
600
+ console.log(`\n Then run this command again.\n`);
601
+ }
602
+ return;
603
+ }
604
+
605
+ if (!opts.json) {
606
+ console.log(` ETH balance: ${balance.eth} ✓`);
607
+ console.log(`\n Starting registration...\n`);
608
+ }
609
+
610
+ // Step 3: Complete onboarding
611
+ try {
612
+ const result = await completeOnboarding(options, wallet);
613
+
614
+ if (opts.json) {
615
+ console.log(JSON.stringify(result, (key, value) =>
616
+ typeof value === "bigint" ? value.toString() : value
617
+ , 2));
618
+ } else {
619
+ console.log(`\n✅ Agent "${opts.name}" fully onboarded!\n`);
620
+ console.log(` Wallet: ${result.wallet.address}`);
621
+ console.log(` ERC-8004: agentId #${result.erc8004.agentId}`);
622
+ if (result.basename) {
623
+ console.log(` Basename: ${result.basename.fullName}`);
624
+ }
625
+ console.log(` Records: ${Object.keys(result.ensRecords.records).length} ENS text records`);
626
+ if (result.kompassRegistry) {
627
+ console.log(` Registry: registered on Kompass`);
628
+ }
629
+ console.log();
630
+ }
631
+ } catch (err: any) {
632
+ if (opts.json) {
633
+ console.log(JSON.stringify({ error: err.message }));
634
+ } else {
635
+ console.error(`\n❌ Onboarding failed: ${err.message}\n`);
636
+ }
637
+ process.exit(1);
638
+ }
639
+ });
640
+
528
641
  // ── Run ──────────────────────────────────────────────────
529
642
 
530
643
  program.parse();
package/src/erc8004.ts ADDED
@@ -0,0 +1,253 @@
1
+ /**
2
+ * ERC-8004 Identity Registry — On-chain agent identity
3
+ *
4
+ * Contract: 0x8004A169FB4a3325136EB29fA0ceB6D2e539a432 (Base mainnet + 20 chains)
5
+ * Each agent gets a unique uint256 agentId (ERC-721 NFT) + agentURI pointing to metadata JSON.
6
+ */
7
+
8
+ import type { Address, Hex } from "viem";
9
+ import type { KompassWallet } from "./wallet/index.js";
10
+
11
+ // ── Contract addresses ─────────────────────────────────────
12
+ export const ERC8004_IDENTITY_REGISTRY: Address = "0x8004A169FB4a3325136EB29fA0ceB6D2e539a432";
13
+
14
+ // ── ABI (minimal — only the functions we need) ─────────────
15
+ export const ERC8004IdentityAbi = [
16
+ {
17
+ type: "function",
18
+ name: "register",
19
+ inputs: [{ name: "agentURI", type: "string" }],
20
+ outputs: [{ name: "agentId", type: "uint256" }],
21
+ stateMutability: "nonpayable",
22
+ },
23
+ {
24
+ type: "function",
25
+ name: "setAgentURI",
26
+ inputs: [
27
+ { name: "agentId", type: "uint256" },
28
+ { name: "newURI", type: "string" },
29
+ ],
30
+ outputs: [],
31
+ stateMutability: "nonpayable",
32
+ },
33
+ {
34
+ type: "function",
35
+ name: "tokenURI",
36
+ inputs: [{ name: "tokenId", type: "uint256" }],
37
+ outputs: [{ name: "", type: "string" }],
38
+ stateMutability: "view",
39
+ },
40
+ {
41
+ type: "function",
42
+ name: "ownerOf",
43
+ inputs: [{ name: "tokenId", type: "uint256" }],
44
+ outputs: [{ name: "", type: "address" }],
45
+ stateMutability: "view",
46
+ },
47
+ {
48
+ type: "function",
49
+ name: "balanceOf",
50
+ inputs: [{ name: "owner", type: "address" }],
51
+ outputs: [{ name: "", type: "uint256" }],
52
+ stateMutability: "view",
53
+ },
54
+ {
55
+ type: "function",
56
+ name: "getAgentWallet",
57
+ inputs: [{ name: "agentId", type: "uint256" }],
58
+ outputs: [{ name: "", type: "address" }],
59
+ stateMutability: "view",
60
+ },
61
+ {
62
+ type: "function",
63
+ name: "setMetadata",
64
+ inputs: [
65
+ { name: "agentId", type: "uint256" },
66
+ { name: "metadataKey", type: "string" },
67
+ { name: "metadataValue", type: "bytes" },
68
+ ],
69
+ outputs: [],
70
+ stateMutability: "nonpayable",
71
+ },
72
+ {
73
+ type: "function",
74
+ name: "getMetadata",
75
+ inputs: [
76
+ { name: "agentId", type: "uint256" },
77
+ { name: "metadataKey", type: "string" },
78
+ ],
79
+ outputs: [{ name: "", type: "bytes" }],
80
+ stateMutability: "view",
81
+ },
82
+ {
83
+ type: "event",
84
+ name: "Registered",
85
+ inputs: [
86
+ { name: "agentId", type: "uint256", indexed: true },
87
+ { name: "agentURI", type: "string", indexed: false },
88
+ { name: "owner", type: "address", indexed: true },
89
+ ],
90
+ },
91
+ ] as const;
92
+
93
+ // ── Types ──────────────────────────────────────────────────
94
+
95
+ export interface AgentCard {
96
+ name: string;
97
+ description: string;
98
+ capabilities: string[];
99
+ categories: string[];
100
+ endpoints?: {
101
+ mcp?: string;
102
+ a2a?: string;
103
+ x402?: string;
104
+ http?: string;
105
+ };
106
+ paymentAddress: Address;
107
+ image?: string;
108
+ }
109
+
110
+ export interface RegisterERC8004Result {
111
+ agentId: bigint;
112
+ txHash: Hex;
113
+ agentURI: string;
114
+ }
115
+
116
+ // ── Functions ──────────────────────────────────────────────
117
+
118
+ /**
119
+ * Register an agent on the ERC-8004 Identity Registry.
120
+ *
121
+ * @param wallet — KompassWallet with funded account
122
+ * @param agentURI — HTTPS or IPFS URL pointing to agent card JSON
123
+ * @param registryAddress — Override registry address (defaults to Base mainnet)
124
+ */
125
+ export async function registerERC8004(
126
+ wallet: KompassWallet,
127
+ agentURI: string,
128
+ registryAddress: Address = ERC8004_IDENTITY_REGISTRY,
129
+ ): Promise<RegisterERC8004Result> {
130
+ const walletClient = wallet.getWalletClient() as any;
131
+ const publicClient = wallet.getPublicClient() as any;
132
+
133
+ const txHash = await walletClient.writeContract({
134
+ address: registryAddress,
135
+ abi: ERC8004IdentityAbi,
136
+ functionName: "register",
137
+ args: [agentURI],
138
+ });
139
+
140
+ const receipt = await publicClient.waitForTransactionReceipt({ hash: txHash });
141
+
142
+ // Parse agentId from Registered event log
143
+ // Registered(uint256 indexed agentId, string agentURI, address indexed owner)
144
+ // Event signature: keccak256("Registered(uint256,string,address)")
145
+ const REGISTERED_EVENT_SIG = "0x" + "d26eab7e9772dfa4e0f4cd96d3f0e9e4e2e4e9e4" as string; // placeholder
146
+ let agentId = 0n;
147
+ for (const log of receipt.logs) {
148
+ if (log.address.toLowerCase() === registryAddress.toLowerCase() && log.topics.length >= 2) {
149
+ // Check that this isn't a Transfer event (ERC-721 Transfer has 4 topics)
150
+ // Registered has 3 topics (sig + agentId + owner), Transfer has 4 (sig + from + to + tokenId)
151
+ // For safety, just grab the first non-Transfer event from this address
152
+ if (log.topics.length === 3) {
153
+ agentId = BigInt(log.topics[1]);
154
+ break;
155
+ }
156
+ }
157
+ }
158
+
159
+ if (agentId === 0n) {
160
+ // Fallback: try any log with 2+ topics from the registry
161
+ for (const log of receipt.logs) {
162
+ if (log.address.toLowerCase() === registryAddress.toLowerCase() && log.topics.length >= 2) {
163
+ agentId = BigInt(log.topics[1]);
164
+ break;
165
+ }
166
+ }
167
+ if (agentId === 0n) {
168
+ console.warn("[erc8004] Could not parse agentId from Registered event logs");
169
+ }
170
+ }
171
+
172
+ return { agentId, txHash, agentURI };
173
+ }
174
+
175
+ /**
176
+ * Update the agent URI for an existing agent.
177
+ */
178
+ export async function setAgentURI(
179
+ wallet: KompassWallet,
180
+ agentId: bigint,
181
+ newURI: string,
182
+ registryAddress: Address = ERC8004_IDENTITY_REGISTRY,
183
+ ): Promise<Hex> {
184
+ const walletClient = wallet.getWalletClient() as any;
185
+ const publicClient = wallet.getPublicClient() as any;
186
+
187
+ const txHash = await walletClient.writeContract({
188
+ address: registryAddress,
189
+ abi: ERC8004IdentityAbi,
190
+ functionName: "setAgentURI",
191
+ args: [agentId, newURI],
192
+ });
193
+
194
+ await publicClient.waitForTransactionReceipt({ hash: txHash });
195
+ return txHash;
196
+ }
197
+
198
+ /**
199
+ * Get the agent URI (metadata JSON URL) for a given agentId.
200
+ */
201
+ export async function getAgentURI(
202
+ wallet: KompassWallet,
203
+ agentId: bigint,
204
+ registryAddress: Address = ERC8004_IDENTITY_REGISTRY,
205
+ ): Promise<string> {
206
+ const publicClient = wallet.getPublicClient() as any;
207
+
208
+ return publicClient.readContract({
209
+ address: registryAddress,
210
+ abi: ERC8004IdentityAbi,
211
+ functionName: "tokenURI",
212
+ args: [agentId],
213
+ });
214
+ }
215
+
216
+ /**
217
+ * Get the owner of an agent NFT.
218
+ */
219
+ export async function getAgentOwner(
220
+ wallet: KompassWallet,
221
+ agentId: bigint,
222
+ registryAddress: Address = ERC8004_IDENTITY_REGISTRY,
223
+ ): Promise<Address> {
224
+ const publicClient = wallet.getPublicClient() as any;
225
+
226
+ return publicClient.readContract({
227
+ address: registryAddress,
228
+ abi: ERC8004IdentityAbi,
229
+ functionName: "ownerOf",
230
+ args: [agentId],
231
+ });
232
+ }
233
+
234
+ /**
235
+ * Build an agent card JSON object for use as agentURI content.
236
+ */
237
+ export function buildAgentCard(options: {
238
+ name: string;
239
+ description: string;
240
+ capabilities: string[];
241
+ categories: string[];
242
+ walletAddress: Address;
243
+ endpoints?: AgentCard["endpoints"];
244
+ }): AgentCard {
245
+ return {
246
+ name: options.name,
247
+ description: options.description,
248
+ capabilities: options.capabilities,
249
+ categories: options.categories,
250
+ paymentAddress: options.walletAddress,
251
+ endpoints: options.endpoints,
252
+ };
253
+ }
package/src/index.ts CHANGED
@@ -243,3 +243,15 @@ export { CapabilityRouter } from "./router.js";
243
243
  export type { DoOptions, DoResult, CapabilityOption, CostPreference } from "./router.js";
244
244
  export { createAllSources } from "./sources/index.js";
245
245
  export type { UnifiedAgent, AgentSource, AgentProtocol, SourceAdapter } from "./sources/types.js";
246
+
247
+ // ERC-8004 Identity Registration
248
+ export { registerERC8004, setAgentURI, getAgentURI, getAgentOwner, buildAgentCard, ERC8004_IDENTITY_REGISTRY } from "./erc8004.js";
249
+ export type { AgentCard, RegisterERC8004Result } from "./erc8004.js";
250
+
251
+ // Basename Registration
252
+ export { registerBasename, isBasenameAvailable, getBasenamePrice, basenameNode, setBasenameTextRecords, getBasenameText, BASENAME_REGISTRAR, BASENAME_L2_RESOLVER } from "./basename.js";
253
+ export type { BasenameResult, TextRecord } from "./basename.js";
254
+
255
+ // Agent Onboarding (full identity flow)
256
+ export { initOnboarding, completeOnboarding, onboardAgent, checkOnboardingFunds, estimateOnboardingCost } from "./onboard.js";
257
+ export type { OnboardOptions, OnboardResult, OnboardInitResult } from "./onboard.js";
package/src/matching.ts CHANGED
@@ -173,13 +173,13 @@ function multiCriteriaScore(agent: UnifiedAgent): number {
173
173
  // Agents from sources we KNOW are live gateways (not just registrations)
174
174
  switch (agent.source as string) {
175
175
  case "bankr":
176
- score += 15; // Bankr is a live gateway, always responds
176
+ score += 25; // Bankr is a live gateway, always responds, verified working
177
177
  break;
178
178
  case "locus":
179
- score += 12; // Locus wrapped APIs are live
179
+ score += 20; // Locus wrapped APIs are live, verified working
180
180
  break;
181
181
  case "x402-ecosystem":
182
- score += 10; // 402index verifies health
182
+ score += 18; // 402index verifies health, real payments
183
183
  break;
184
184
  case "acp":
185
185
  score += 8; // ACP agents are registered and active
@@ -188,9 +188,10 @@ function multiCriteriaScore(agent: UnifiedAgent): number {
188
188
  score += 8; // Olas mechs have on-chain delivery records
189
189
  break;
190
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
191
+ // Most MCP servers on Smithery require auth or are offline
192
+ // Only boost if it has a remote endpoint, but still penalize vs verified live sources
193
+ if (hasMcp) score += 0; // Neutral might work, might not
194
+ else score -= 10; // No remote endpoint = definitely can't call
194
195
  break;
195
196
  case "erc8004":
196
197
  // ERC-8004 is a registry — agents may or may not be live