kompass-sdk 0.13.0 → 0.15.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.
Files changed (58) hide show
  1. package/dist/cli.js +0 -0
  2. package/dist/matching.d.ts.map +1 -1
  3. package/dist/matching.js +8 -0
  4. package/dist/matching.js.map +1 -1
  5. package/dist/sources/acp.js +1 -1
  6. package/dist/sources/acp.js.map +1 -1
  7. package/dist/sources/bankr.d.ts +8 -0
  8. package/dist/sources/bankr.d.ts.map +1 -0
  9. package/dist/sources/bankr.js +79 -0
  10. package/dist/sources/bankr.js.map +1 -0
  11. package/dist/sources/index.d.ts.map +1 -1
  12. package/dist/sources/index.js +4 -0
  13. package/dist/sources/index.js.map +1 -1
  14. package/dist/sources/locus.d.ts +12 -0
  15. package/dist/sources/locus.d.ts.map +1 -0
  16. package/dist/sources/locus.js +134 -0
  17. package/dist/sources/locus.js.map +1 -0
  18. package/dist/sources/mcp-registry.d.ts +2 -2
  19. package/dist/sources/mcp-registry.d.ts.map +1 -1
  20. package/dist/sources/mcp-registry.js +89 -81
  21. package/dist/sources/mcp-registry.js.map +1 -1
  22. package/dist/sources/openserv.d.ts +8 -0
  23. package/dist/sources/openserv.d.ts.map +1 -0
  24. package/dist/sources/openserv.js +76 -0
  25. package/dist/sources/openserv.js.map +1 -0
  26. package/dist/sources/types.d.ts +1 -1
  27. package/dist/sources/types.d.ts.map +1 -1
  28. package/dist/wallet/bridge.d.ts +1 -0
  29. package/dist/wallet/bridge.d.ts.map +1 -1
  30. package/dist/wallet/bridge.js +31 -5
  31. package/dist/wallet/bridge.js.map +1 -1
  32. package/dist/wallet/handlers/acp.d.ts.map +1 -1
  33. package/dist/wallet/handlers/acp.js +59 -3
  34. package/dist/wallet/handlers/acp.js.map +1 -1
  35. package/dist/wallet/handlers/bankr.d.ts +13 -0
  36. package/dist/wallet/handlers/bankr.d.ts.map +1 -0
  37. package/dist/wallet/handlers/bankr.js +88 -0
  38. package/dist/wallet/handlers/bankr.js.map +1 -0
  39. package/dist/wallet/handlers/locus.d.ts +21 -0
  40. package/dist/wallet/handlers/locus.d.ts.map +1 -0
  41. package/dist/wallet/handlers/locus.js +144 -0
  42. package/dist/wallet/handlers/locus.js.map +1 -0
  43. package/dist/wallet/payment-router.d.ts.map +1 -1
  44. package/dist/wallet/payment-router.js +12 -0
  45. package/dist/wallet/payment-router.js.map +1 -1
  46. package/package.json +1 -1
  47. package/src/matching.ts +9 -0
  48. package/src/sources/acp.ts +1 -1
  49. package/src/sources/bankr.ts +87 -0
  50. package/src/sources/index.ts +4 -0
  51. package/src/sources/locus.ts +156 -0
  52. package/src/sources/mcp-registry.ts +108 -99
  53. package/src/sources/types.ts +3 -1
  54. package/src/wallet/bridge.ts +33 -6
  55. package/src/wallet/handlers/acp.ts +69 -3
  56. package/src/wallet/handlers/bankr.ts +108 -0
  57. package/src/wallet/handlers/locus.ts +170 -0
  58. package/src/wallet/payment-router.ts +14 -0
@@ -0,0 +1,170 @@
1
+ /**
2
+ * Locus Payment Handler
3
+ * Calls Locus wrapped APIs — pay-per-use via USDC on Base.
4
+ * No upstream API keys needed — Locus proxies the call and charges the wallet.
5
+ *
6
+ * Flow:
7
+ * 1. Get or create Locus API key (self-register if needed)
8
+ * 2. Wait for wallet deployment
9
+ * 3. Call the wrapped API endpoint
10
+ * 4. Locus charges USDC from wallet, returns response
11
+ *
12
+ * Docs: https://beta.paywithlocus.com/skill.md
13
+ */
14
+
15
+ import type { KompassWallet } from "../index.js";
16
+ import type { UnifiedAgent } from "../../sources/types.js";
17
+
18
+ const LOCUS_API = "https://beta-api.paywithlocus.com/api";
19
+
20
+ export async function handleLocusPayment(
21
+ wallet: KompassWallet,
22
+ agent: UnifiedAgent,
23
+ task: string,
24
+ ): Promise<{ success: boolean; deliverable?: unknown; txHash?: string }> {
25
+ let apiKey = process.env.LOCUS_API_KEY;
26
+
27
+ try {
28
+ // Step 1: Self-register if no API key
29
+ if (!apiKey) {
30
+ const walletAddress = wallet.getAddress();
31
+ const registerRes = await fetch(`${LOCUS_API}/register`, {
32
+ method: "POST",
33
+ headers: { "Content-Type": "application/json" },
34
+ body: JSON.stringify({
35
+ wallet_address: walletAddress,
36
+ agent_name: "kompass-agent",
37
+ }),
38
+ signal: AbortSignal.timeout(15000),
39
+ });
40
+
41
+ if (!registerRes.ok) {
42
+ const errBody = await registerRes.text().catch(() => "");
43
+ return {
44
+ success: false,
45
+ deliverable: {
46
+ error: `Locus registration failed: ${registerRes.status}`,
47
+ details: errBody,
48
+ hint: "Set LOCUS_API_KEY env var or fund a Locus wallet at paywithlocus.com",
49
+ },
50
+ };
51
+ }
52
+
53
+ const registerData = await registerRes.json();
54
+ apiKey = registerData.data?.apiKey;
55
+
56
+ if (!apiKey) {
57
+ return {
58
+ success: false,
59
+ deliverable: { error: "Locus registration did not return an API key" },
60
+ };
61
+ }
62
+
63
+ // Wait for wallet deployment
64
+ for (let i = 0; i < 10; i++) {
65
+ const statusRes = await fetch(`${LOCUS_API}/status`, {
66
+ headers: { "Authorization": `Bearer ${apiKey}` },
67
+ signal: AbortSignal.timeout(5000),
68
+ }).catch(() => null);
69
+
70
+ if (statusRes?.ok) {
71
+ const statusData = await statusRes.json();
72
+ if (statusData.data?.walletStatus === "deployed") break;
73
+ }
74
+ await new Promise((r) => setTimeout(r, 3000));
75
+ }
76
+ }
77
+
78
+ const headers: Record<string, string> = {
79
+ "Content-Type": "application/json",
80
+ "Authorization": `Bearer ${apiKey}`,
81
+ };
82
+
83
+ // Step 2: Determine if this is a wrapped API call or a direct payment
84
+ const rawData = agent.raw as any;
85
+ const isWrappedApi = rawData?.type === "locus-wrapped-api";
86
+
87
+ if (isWrappedApi) {
88
+ // Call the wrapped API directly
89
+ // The endpoint URL is like: /api/wrapped/{provider}/{endpoint}
90
+ // We need to figure out the best endpoint for the task
91
+ const provider = rawData.provider;
92
+ const availableEndpoints = rawData.endpoints as string[] || [];
93
+
94
+ // Pick the first/most relevant endpoint
95
+ // For now use the first endpoint — the provider slug is already in the URL
96
+ const endpoint = availableEndpoints[0]?.toLowerCase().replace(/\s+/g, "-") || "search";
97
+
98
+ const callUrl = `${LOCUS_API}/wrapped/${provider}/${endpoint}`;
99
+
100
+ const callRes = await fetch(callUrl, {
101
+ method: "POST",
102
+ headers,
103
+ body: JSON.stringify({ query: task, prompt: task, q: task }),
104
+ signal: AbortSignal.timeout(30000),
105
+ });
106
+
107
+ if (!callRes.ok) {
108
+ const errBody = await callRes.text().catch(() => "");
109
+ return {
110
+ success: false,
111
+ deliverable: {
112
+ error: `Locus wrapped API call failed: ${callRes.status}`,
113
+ provider,
114
+ endpoint,
115
+ details: errBody,
116
+ },
117
+ };
118
+ }
119
+
120
+ const result = await callRes.json();
121
+ return {
122
+ success: true,
123
+ deliverable: result,
124
+ };
125
+ }
126
+
127
+ // Step 3: Direct USDC payment to agent address
128
+ const toAddress = agent.endpoints.acp?.walletAddress ?? agent.endpoints.http;
129
+ const amount = agent.pricing?.amount ?? "0.01";
130
+
131
+ if (!toAddress || !toAddress.startsWith("0x")) {
132
+ return {
133
+ success: false,
134
+ deliverable: { error: "No valid target address for Locus payment" },
135
+ };
136
+ }
137
+
138
+ const sendRes = await fetch(`${LOCUS_API}/pay/send`, {
139
+ method: "POST",
140
+ headers,
141
+ body: JSON.stringify({
142
+ to_address: toAddress,
143
+ amount: parseFloat(amount),
144
+ memo: `Kompass task: ${task.slice(0, 100)}`,
145
+ }),
146
+ signal: AbortSignal.timeout(30000),
147
+ });
148
+
149
+ if (!sendRes.ok) {
150
+ const errBody = await sendRes.text().catch(() => "");
151
+ return {
152
+ success: false,
153
+ deliverable: { error: `Locus payment failed: ${sendRes.status}`, details: errBody },
154
+ };
155
+ }
156
+
157
+ const sendData = await sendRes.json();
158
+
159
+ return {
160
+ success: true,
161
+ deliverable: sendData,
162
+ txHash: sendData.data?.tx_hash ?? sendData.data?.transaction_id,
163
+ };
164
+ } catch (err) {
165
+ return {
166
+ success: false,
167
+ deliverable: { error: err instanceof Error ? err.message : String(err) },
168
+ };
169
+ }
170
+ }
@@ -11,6 +11,8 @@ import { handleL402Payment } from "./handlers/l402.js";
11
11
  import { handleMPPPayment } from "./handlers/mpp.js";
12
12
  import { handleNanopayment } from "./handlers/nanopayments.js";
13
13
  import { handleFreePayment } from "./handlers/free.js";
14
+ import { handleBankrPayment } from "./handlers/bankr.js";
15
+ import { handleLocusPayment } from "./handlers/locus.js";
14
16
  import { ensureSufficientBalance } from "./bridge.js";
15
17
 
16
18
  export interface PaymentResult {
@@ -72,6 +74,16 @@ export async function routePayment(
72
74
  return { ...result, protocol: "circle-nanopayments", costUSDC: parseFloat(agent.pricing?.amount ?? "0") };
73
75
  }
74
76
 
77
+ case "bankr": {
78
+ const result = await handleBankrPayment(wallet, agent, task);
79
+ return { ...result, protocol: "bankr", costUSDC: parseFloat(agent.pricing?.amount ?? "0") };
80
+ }
81
+
82
+ case "locus": {
83
+ const result = await handleLocusPayment(wallet, agent, task);
84
+ return { ...result, protocol: "locus", costUSDC: parseFloat(agent.pricing?.amount ?? "0") };
85
+ }
86
+
75
87
  case "free":
76
88
  case "mcp": {
77
89
  // MCP servers and free tools — try to execute directly
@@ -130,6 +142,8 @@ function determinePaymentProtocol(agent: UnifiedAgent): string {
130
142
  case "l402-directory": return "l402";
131
143
  case "mcp-registry": return "free";
132
144
  case "skills-registry": return "free";
145
+ case "bankr": return "bankr";
146
+ case "locus": return "locus";
133
147
  default: return agent.protocol === "onchain" ? "acp" : "free";
134
148
  }
135
149
  }