@agentxv2/sdk 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.
- package/README.md +25 -16
- package/dist/core.d.mts +64 -0
- package/dist/core.d.ts +64 -0
- package/dist/core.js +275 -0
- package/dist/core.js.map +1 -0
- package/dist/core.mjs +240 -0
- package/dist/core.mjs.map +1 -0
- package/dist/{agent/agent-runner.d.ts → index-DhXVi_ub.d.ts} +94 -10
- package/dist/index-eQO4iaOr.d.mts +208 -0
- package/dist/index.d.mts +269 -0
- package/dist/index.d.ts +269 -10
- package/dist/index.js +2416 -31
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2363 -0
- package/dist/index.mjs.map +1 -0
- package/dist/react.d.mts +3 -0
- package/dist/react.d.ts +3 -0
- package/dist/react.js +755 -0
- package/dist/react.js.map +1 -0
- package/dist/react.mjs +735 -0
- package/dist/react.mjs.map +1 -0
- package/dist/{core/types.d.ts → types-2aHUvS4M.d.mts} +34 -33
- package/dist/types-2aHUvS4M.d.ts +297 -0
- package/package.json +12 -11
- package/dist/a2a/a2a.d.ts +0 -37
- package/dist/a2a/a2a.d.ts.map +0 -1
- package/dist/a2a/a2a.js +0 -252
- package/dist/a2a/a2a.js.map +0 -1
- package/dist/a2a/index.d.ts +0 -4
- package/dist/a2a/index.d.ts.map +0 -1
- package/dist/a2a/index.js +0 -4
- package/dist/a2a/index.js.map +0 -1
- package/dist/agent/agent-runner.d.ts.map +0 -1
- package/dist/agent/agent-runner.js +0 -249
- package/dist/agent/agent-runner.js.map +0 -1
- package/dist/agent/index.d.ts +0 -3
- package/dist/agent/index.d.ts.map +0 -1
- package/dist/agent/index.js +0 -3
- package/dist/agent/index.js.map +0 -1
- package/dist/config/config.d.ts +0 -31
- package/dist/config/config.d.ts.map +0 -1
- package/dist/config/config.js +0 -95
- package/dist/config/config.js.map +0 -1
- package/dist/config/index.d.ts +0 -4
- package/dist/config/index.d.ts.map +0 -1
- package/dist/config/index.js +0 -4
- package/dist/config/index.js.map +0 -1
- package/dist/core/crypto.d.ts +0 -62
- package/dist/core/crypto.d.ts.map +0 -1
- package/dist/core/crypto.js +0 -291
- package/dist/core/crypto.js.map +0 -1
- package/dist/core/index.d.ts +0 -3
- package/dist/core/index.d.ts.map +0 -1
- package/dist/core/index.js +0 -4
- package/dist/core/index.js.map +0 -1
- package/dist/core/types.d.ts.map +0 -1
- package/dist/core/types.js +0 -30
- package/dist/core/types.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/mcp/connector.d.ts +0 -43
- package/dist/mcp/connector.d.ts.map +0 -1
- package/dist/mcp/connector.js +0 -79
- package/dist/mcp/connector.js.map +0 -1
- package/dist/mcp/index.d.ts +0 -4
- package/dist/mcp/index.d.ts.map +0 -1
- package/dist/mcp/index.js +0 -4
- package/dist/mcp/index.js.map +0 -1
- package/dist/react/index.d.ts +0 -4
- package/dist/react/index.d.ts.map +0 -1
- package/dist/react/index.js +0 -3
- package/dist/react/index.js.map +0 -1
- package/dist/react/useAgentRunner.d.ts +0 -16
- package/dist/react/useAgentRunner.d.ts.map +0 -1
- package/dist/react/useAgentRunner.js +0 -204
- package/dist/react/useAgentRunner.js.map +0 -1
- package/dist/registry/agent-registry.d.ts +0 -52
- package/dist/registry/agent-registry.d.ts.map +0 -1
- package/dist/registry/agent-registry.js +0 -221
- package/dist/registry/agent-registry.js.map +0 -1
- package/dist/registry/index.d.ts +0 -7
- package/dist/registry/index.d.ts.map +0 -1
- package/dist/registry/index.js +0 -6
- package/dist/registry/index.js.map +0 -1
- package/dist/registry/ipfs-fetcher.d.ts +0 -39
- package/dist/registry/ipfs-fetcher.d.ts.map +0 -1
- package/dist/registry/ipfs-fetcher.js +0 -139
- package/dist/registry/ipfs-fetcher.js.map +0 -1
- package/dist/reputation/index.d.ts +0 -4
- package/dist/reputation/index.d.ts.map +0 -1
- package/dist/reputation/index.js +0 -4
- package/dist/reputation/index.js.map +0 -1
- package/dist/reputation/reputation.d.ts +0 -26
- package/dist/reputation/reputation.d.ts.map +0 -1
- package/dist/reputation/reputation.js +0 -113
- package/dist/reputation/reputation.js.map +0 -1
- package/dist/subscription/agent-x402.d.ts +0 -33
- package/dist/subscription/agent-x402.d.ts.map +0 -1
- package/dist/subscription/agent-x402.js +0 -144
- package/dist/subscription/agent-x402.js.map +0 -1
- package/dist/subscription/index.d.ts +0 -6
- package/dist/subscription/index.d.ts.map +0 -1
- package/dist/subscription/index.js +0 -5
- package/dist/subscription/index.js.map +0 -1
- package/dist/subscription/subscription.d.ts +0 -67
- package/dist/subscription/subscription.d.ts.map +0 -1
- package/dist/subscription/subscription.js +0 -346
- package/dist/subscription/subscription.js.map +0 -1
package/dist/core.mjs
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
+
}) : x)(function(x) {
|
|
4
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
// src/core/types.ts
|
|
9
|
+
var AgentXErrorCode = /* @__PURE__ */ ((AgentXErrorCode2) => {
|
|
10
|
+
AgentXErrorCode2["NOT_SUBSCRIBED"] = "NOT_SUBSCRIBED";
|
|
11
|
+
AgentXErrorCode2["SUBSCRIPTION_EXPIRED"] = "SUBSCRIPTION_EXPIRED";
|
|
12
|
+
AgentXErrorCode2["DECRYPTION_FAILED"] = "DECRYPTION_FAILED";
|
|
13
|
+
AgentXErrorCode2["IPFS_FETCH_FAILED"] = "IPFS_FETCH_FAILED";
|
|
14
|
+
AgentXErrorCode2["AGENT_NOT_FOUND"] = "AGENT_NOT_FOUND";
|
|
15
|
+
AgentXErrorCode2["INVALID_SCHEMA"] = "INVALID_SCHEMA";
|
|
16
|
+
AgentXErrorCode2["TX_FAILED"] = "TX_FAILED";
|
|
17
|
+
AgentXErrorCode2["WALLET_NOT_CONNECTED"] = "WALLET_NOT_CONNECTED";
|
|
18
|
+
return AgentXErrorCode2;
|
|
19
|
+
})(AgentXErrorCode || {});
|
|
20
|
+
var AgentXError = class extends Error {
|
|
21
|
+
code;
|
|
22
|
+
/** If NOT_SUBSCRIBED, carry enough info for wallet/X402 auto-payment */
|
|
23
|
+
paymentInfo;
|
|
24
|
+
constructor(code, message) {
|
|
25
|
+
super(message);
|
|
26
|
+
this.code = code;
|
|
27
|
+
this.name = "AgentXError";
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
// src/core/crypto.ts
|
|
32
|
+
import { gcm } from "@noble/ciphers/aes.js";
|
|
33
|
+
import { secp256k1 } from "@noble/curves/secp256k1.js";
|
|
34
|
+
import { sha256 } from "@noble/hashes/sha2.js";
|
|
35
|
+
import { hkdf } from "@noble/hashes/hkdf.js";
|
|
36
|
+
import { hmac } from "@noble/hashes/hmac.js";
|
|
37
|
+
import { bytesToHex, hexToBytes } from "@noble/ciphers/utils.js";
|
|
38
|
+
function randomBytes(length) {
|
|
39
|
+
if (typeof crypto !== "undefined" && crypto.getRandomValues) {
|
|
40
|
+
const buf = new Uint8Array(length);
|
|
41
|
+
crypto.getRandomValues(buf);
|
|
42
|
+
return buf;
|
|
43
|
+
}
|
|
44
|
+
const nodeCrypto = __require("crypto");
|
|
45
|
+
return new Uint8Array(nodeCrypto.randomBytes(length));
|
|
46
|
+
}
|
|
47
|
+
var AES_KEY_SIZE = 32;
|
|
48
|
+
var IV_SIZE = 12;
|
|
49
|
+
var TAG_SIZE = 16;
|
|
50
|
+
function toBase64(bytes) {
|
|
51
|
+
if (typeof Buffer !== "undefined") return Buffer.from(bytes).toString("base64");
|
|
52
|
+
let binary = "";
|
|
53
|
+
for (let i = 0; i < bytes.length; i++) binary += String.fromCharCode(bytes[i]);
|
|
54
|
+
return btoa(binary);
|
|
55
|
+
}
|
|
56
|
+
function fromBase64(b64) {
|
|
57
|
+
if (typeof Buffer !== "undefined") return new Uint8Array(Buffer.from(b64, "base64"));
|
|
58
|
+
const binary = atob(b64);
|
|
59
|
+
const bytes = new Uint8Array(binary.length);
|
|
60
|
+
for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
|
|
61
|
+
return bytes;
|
|
62
|
+
}
|
|
63
|
+
function aesEncrypt(plaintext, keyHex) {
|
|
64
|
+
const key = hexToBytes(keyHex);
|
|
65
|
+
const iv = randomBytes(IV_SIZE);
|
|
66
|
+
const plainBytes = new TextEncoder().encode(plaintext);
|
|
67
|
+
const cipher = gcm(key, iv);
|
|
68
|
+
const encrypted = cipher.encrypt(plainBytes);
|
|
69
|
+
const ciphertext = encrypted.subarray(0, -TAG_SIZE);
|
|
70
|
+
const authTag = encrypted.subarray(-TAG_SIZE);
|
|
71
|
+
const combined = new Uint8Array(IV_SIZE + ciphertext.length + TAG_SIZE);
|
|
72
|
+
combined.set(iv, 0);
|
|
73
|
+
combined.set(ciphertext, IV_SIZE);
|
|
74
|
+
combined.set(authTag, IV_SIZE + ciphertext.length);
|
|
75
|
+
return toBase64(combined);
|
|
76
|
+
}
|
|
77
|
+
function aesDecrypt(encryptedBase64, keyHex) {
|
|
78
|
+
const key = hexToBytes(keyHex);
|
|
79
|
+
const combined = fromBase64(encryptedBase64);
|
|
80
|
+
const iv = combined.subarray(0, IV_SIZE);
|
|
81
|
+
const ciphertext = combined.subarray(IV_SIZE, -TAG_SIZE);
|
|
82
|
+
const authTag = combined.subarray(-TAG_SIZE);
|
|
83
|
+
const cipher = gcm(key, iv);
|
|
84
|
+
const ciphertextWithTag = new Uint8Array(ciphertext.length + TAG_SIZE);
|
|
85
|
+
ciphertextWithTag.set(ciphertext, 0);
|
|
86
|
+
ciphertextWithTag.set(authTag, ciphertext.length);
|
|
87
|
+
const decrypted = cipher.decrypt(ciphertextWithTag);
|
|
88
|
+
return new TextDecoder().decode(decrypted);
|
|
89
|
+
}
|
|
90
|
+
function generateAesKey() {
|
|
91
|
+
return bytesToHex(randomBytes(AES_KEY_SIZE));
|
|
92
|
+
}
|
|
93
|
+
function eciesEncode(ephemeralPub, iv, ciphertext, mac) {
|
|
94
|
+
const out = new Uint8Array(33 + 16 + ciphertext.length + 32);
|
|
95
|
+
out.set(ephemeralPub, 0);
|
|
96
|
+
out.set(iv, 33);
|
|
97
|
+
out.set(ciphertext, 33 + 16);
|
|
98
|
+
out.set(mac, 33 + 16 + ciphertext.length);
|
|
99
|
+
return bytesToHex(out);
|
|
100
|
+
}
|
|
101
|
+
function eciesDecode(dataHex) {
|
|
102
|
+
const d = hexToBytes(dataHex);
|
|
103
|
+
return {
|
|
104
|
+
ephemeralPub: d.subarray(0, 33),
|
|
105
|
+
iv: d.subarray(33, 49),
|
|
106
|
+
ciphertext: d.subarray(49, -32),
|
|
107
|
+
mac: d.subarray(-32)
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
function aesCtrEncrypt(key, ctrBytes, data) {
|
|
111
|
+
const blockSize = 16;
|
|
112
|
+
const cipher = gcm(key, ctrBytes);
|
|
113
|
+
const result = new Uint8Array(data.length);
|
|
114
|
+
const counter = new Uint8Array(blockSize);
|
|
115
|
+
counter.set(ctrBytes);
|
|
116
|
+
for (let i = 0; i < data.length; i += blockSize) {
|
|
117
|
+
const keystream = gcm(key, counter).encrypt(new Uint8Array(blockSize));
|
|
118
|
+
for (let j = 0; j < blockSize && i + j < data.length; j++) {
|
|
119
|
+
result[i + j] = keystream[j] ^ data[i + j];
|
|
120
|
+
}
|
|
121
|
+
for (let j = blockSize - 1; j >= 0; j--) {
|
|
122
|
+
const val = counter[j];
|
|
123
|
+
if (val !== void 0) {
|
|
124
|
+
counter[j] = val + 1 & 255;
|
|
125
|
+
if (counter[j] !== 0) break;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return result;
|
|
130
|
+
}
|
|
131
|
+
function eciesEncrypt(dataHex, publicKey) {
|
|
132
|
+
const ephPriv = randomBytes(32);
|
|
133
|
+
const ephPub = secp256k1.getPublicKey(ephPriv, true);
|
|
134
|
+
let recipientPub;
|
|
135
|
+
if (publicKey.startsWith("04") && publicKey.length === 130) {
|
|
136
|
+
recipientPub = hexToBytes(publicKey);
|
|
137
|
+
} else if (publicKey.startsWith("02") || publicKey.startsWith("03")) {
|
|
138
|
+
recipientPub = hexToBytes(publicKey);
|
|
139
|
+
} else {
|
|
140
|
+
throw new Error("Invalid public key format: expected hex with 02/03/04 prefix");
|
|
141
|
+
}
|
|
142
|
+
const shared = secp256k1.getSharedSecret(ephPriv, recipientPub);
|
|
143
|
+
const sharedX = shared.subarray(1, 33);
|
|
144
|
+
const sharedKey = sha256(sharedX);
|
|
145
|
+
const hkdfOut = hkdf(sha256, sharedKey, void 0, void 0, 64);
|
|
146
|
+
const encKey = hkdfOut.subarray(0, 32);
|
|
147
|
+
const macKey = hkdfOut.subarray(32, 64);
|
|
148
|
+
const iv = randomBytes(16);
|
|
149
|
+
const plaintext = hexToBytes(dataHex);
|
|
150
|
+
const ciphertext = aesCtrEncrypt(encKey, iv, plaintext);
|
|
151
|
+
const macInput = new Uint8Array(33 + 16 + ciphertext.length);
|
|
152
|
+
macInput.set(ephPub, 0);
|
|
153
|
+
macInput.set(iv, 33);
|
|
154
|
+
macInput.set(ciphertext, 33 + 16);
|
|
155
|
+
const mac = hmac(sha256, macKey, macInput);
|
|
156
|
+
return eciesEncode(ephPub, iv, ciphertext, mac);
|
|
157
|
+
}
|
|
158
|
+
function eciesDecrypt(dataHex, privateKey) {
|
|
159
|
+
const { ephemeralPub, iv, ciphertext, mac } = eciesDecode(dataHex);
|
|
160
|
+
const privBytes = hexToBytes(privateKey);
|
|
161
|
+
const shared = secp256k1.getSharedSecret(privBytes, ephemeralPub);
|
|
162
|
+
const sharedX = shared.subarray(1, 33);
|
|
163
|
+
const sharedKey = sha256(sharedX);
|
|
164
|
+
const hkdfOut = hkdf(sha256, sharedKey, void 0, void 0, 64);
|
|
165
|
+
const encKey = hkdfOut.subarray(0, 32);
|
|
166
|
+
const macKey = hkdfOut.subarray(32, 64);
|
|
167
|
+
const macInput = new Uint8Array(33 + 16 + ciphertext.length);
|
|
168
|
+
macInput.set(ephemeralPub, 0);
|
|
169
|
+
macInput.set(iv, 33);
|
|
170
|
+
macInput.set(ciphertext, 33 + 16);
|
|
171
|
+
const expectedMac = hmac(sha256, macKey, macInput);
|
|
172
|
+
if (!constantTimeEqual(mac, expectedMac)) {
|
|
173
|
+
throw new Error("ECIES decryption failed: MAC mismatch");
|
|
174
|
+
}
|
|
175
|
+
const plaintext = aesCtrEncrypt(encKey, iv, ciphertext);
|
|
176
|
+
return bytesToHex(plaintext);
|
|
177
|
+
}
|
|
178
|
+
function constantTimeEqual(a, b) {
|
|
179
|
+
if (a.length !== b.length) return false;
|
|
180
|
+
let diff = 0;
|
|
181
|
+
for (let i = 0; i < a.length; i++) diff |= a[i] ^ b[i];
|
|
182
|
+
return diff === 0;
|
|
183
|
+
}
|
|
184
|
+
function encryptPayload(payload, keyHex) {
|
|
185
|
+
const key = keyHex ?? generateAesKey();
|
|
186
|
+
return {
|
|
187
|
+
encrypted: true,
|
|
188
|
+
algorithm: "AES-256-GCM",
|
|
189
|
+
data: aesEncrypt(JSON.stringify(payload), key)
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
function decryptPayload(encrypted, keyHex) {
|
|
193
|
+
if (encrypted.algorithm !== "AES-256-GCM") {
|
|
194
|
+
throw new Error(`Unsupported algorithm: ${encrypted.algorithm}`);
|
|
195
|
+
}
|
|
196
|
+
return JSON.parse(aesDecrypt(encrypted.data, keyHex));
|
|
197
|
+
}
|
|
198
|
+
function packAgentForPublish(agent, publicKey, aesKeyHex) {
|
|
199
|
+
const key = aesKeyHex ?? generateAesKey();
|
|
200
|
+
const eciesEncryptedKeyHex = eciesEncrypt(key, publicKey);
|
|
201
|
+
return {
|
|
202
|
+
encryptedCid: "",
|
|
203
|
+
// filled after IPFS upload
|
|
204
|
+
publicCid: "",
|
|
205
|
+
// filled after IPFS upload
|
|
206
|
+
aesKeyHex: key,
|
|
207
|
+
eciesEncryptedKeyHex
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
function unpackAgent(encryptedPayload, eciesEncryptedKey, privateKey) {
|
|
211
|
+
const aesKeyHex = eciesDecrypt(eciesEncryptedKey, privateKey);
|
|
212
|
+
return decryptPayload(encryptedPayload, aesKeyHex);
|
|
213
|
+
}
|
|
214
|
+
function generateKeyPair() {
|
|
215
|
+
const priv = randomBytes(32);
|
|
216
|
+
const pub = secp256k1.getPublicKey(priv, false);
|
|
217
|
+
return { privateKey: bytesToHex(priv), publicKey: bytesToHex(pub) };
|
|
218
|
+
}
|
|
219
|
+
function getPublicKey(privateKey) {
|
|
220
|
+
return bytesToHex(secp256k1.getPublicKey(hexToBytes(privateKey), false));
|
|
221
|
+
}
|
|
222
|
+
export {
|
|
223
|
+
AgentXError,
|
|
224
|
+
AgentXErrorCode,
|
|
225
|
+
aesDecrypt,
|
|
226
|
+
aesEncrypt,
|
|
227
|
+
bytesToHex,
|
|
228
|
+
decryptPayload,
|
|
229
|
+
eciesDecrypt,
|
|
230
|
+
eciesEncrypt,
|
|
231
|
+
encryptPayload,
|
|
232
|
+
generateAesKey,
|
|
233
|
+
generateKeyPair,
|
|
234
|
+
getPublicKey,
|
|
235
|
+
hexToBytes,
|
|
236
|
+
packAgentForPublish,
|
|
237
|
+
randomBytes,
|
|
238
|
+
unpackAgent
|
|
239
|
+
};
|
|
240
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/core/types.ts","../../src/core/crypto.ts"],"sourcesContent":["// ---------------------------------------------------------------------------\n// @agentx/sdk — Core Type Definitions\n// ---------------------------------------------------------------------------\n// Agent = Prompt + Skills[] + MCP\n// All crypto-related \"wire\" fields (encryptedPayloadCid, eciesEncryptedKey)\n// live in IPFS metadata attributes → existing ERC8004 contracts are unchanged.\n// ---------------------------------------------------------------------------\n\n// ── JSON Schema (MCP standard subset) ──────────────────────────────────────\n\nexport interface JSONSchema {\n type: 'object' | 'array' | 'string' | 'number' | 'boolean' | 'integer' | 'null'\n properties?: Record<string, JSONSchemaProperty>\n required?: string[]\n description?: string\n items?: JSONSchema\n enum?: (string | number | boolean | null)[]\n}\n\nexport interface JSONSchemaProperty {\n type?: JSONSchema['type'] | JSONSchema['type'][]\n description?: string\n properties?: Record<string, JSONSchemaProperty>\n required?: string[]\n items?: JSONSchema\n enum?: (string | number | boolean | null)[]\n format?: string\n default?: unknown\n}\n\n// ── Skill Definition ───────────────────────────────────────────────────────\n\n/**\n * A single skill module that an Agent exposes.\n * `inputSchema` and `outputSchema` follow MCP Tool JSON Schema conventions.\n */\nexport interface SkillDef {\n /** Unique skill name (e.g. \"solidity_audit\") */\n name: string\n /** Human-readable description shown in the marketplace */\n description: string\n /** Semantic version of this skill */\n version: string\n /** JSON Schema for the tool's input parameters */\n inputSchema: JSONSchema\n /** JSON Schema for the tool's output return value */\n outputSchema?: JSONSchema\n /**\n * Execution mode.\n * - undefined / \"open\": Source is in the encrypted payload, runs locally.\n * - { type: \"mcp\", toolName: \"...\" }: Source lives on the publisher's\n * MCP server. Subscriber only gets Schema + remote execution endpoint.\n * MCP server verifies on-chain subscription on every call.\n * - { type: \"a2a\", targetAgentId: 42 }: Delegates to another AgentX Agent.\n * The caller's AgentRunner loads + decrypts the target Agent, injects\n * its prompt into the LLM context, and exposes its skills as callable\n * tools. This is the core Agent Composition primitive.\n */\n execution?: SkillExecutionRemote | A2ASkillExecution\n}\n\n/** Where the skill code actually runs. */\nexport type SkillExecutionMode = 'open' | 'mcp' | 'a2a'\n\nexport interface SkillExecutionRemote {\n type: 'mcp'\n /** MCP tool name on the publisher's server (e.g. \"run_strategy_abc123\") */\n toolName: string\n /** Optional: explicit MCP endpoint override */\n endpoint?: string\n}\n\n/**\n * A2A Skill Execution — delegate to another AgentX Agent.\n *\n * Example: A \"trading\" Agent has a skill:\n * execution: { type: \"a2a\", targetAgentId: 42 }\n * → When LLM calls this skill, AgentRunner loads Agent #42,\n * decrypts its prompt+skills, and the sub-Agent runs in the\n * same LLM conversation with its own system prompt.\n */\nexport interface A2ASkillExecution {\n type: 'a2a'\n /** On-chain Agent ID to delegate to */\n targetAgentId: number\n /** Optional: restrict which of the target Agent's skills are exposed */\n skillFilter?: string[]\n /** Optional: custom system prompt override for the sub-Agent */\n promptOverride?: string\n}\n\n// ── MCP Connection ─────────────────────────────────────────────────────────\n\nexport type McpTransport = 'http' | 'sse' | 'stdio'\n\nexport interface McpConnection {\n /** Transport type */\n type: McpTransport\n /** MCP server URL (required for http/sse) */\n url?: string\n /** Optional: limit which tools the Agent exposes to users */\n toolFilter?: string[]\n /** Optional: MCP server authentication header / key */\n authHeader?: string\n}\n\n// ── Pricing ────────────────────────────────────────────────────────────────\n\nexport type PricingType = 'subscription' | 'pay_per_use' | 'free'\n\nexport interface AgentPricing {\n type: PricingType\n /** Amount in native unit (e.g. \"0.01\" for 0.01 ETH) */\n amount: string\n /** ERC20 token address, or empty for native currency */\n currency: string\n /** Billing period for subscriptions (e.g. \"month\", \"year\", \"day\") */\n period?: string\n}\n\n// ── Agent Payload (the core data model) ────────────────────────────────────\n\n/**\n * The complete Agent definition.\n *\n * - Fields above \"--- private payload ---\" are public (IPFS publicPayloadCid).\n * - Fields below are encrypted with AES-256-GCM and stored at encryptedPayloadCid.\n */\nexport interface AgentPayload {\n // ── Public (visible in marketplace, stored at publicPayloadCid) ─────────\n name: string\n description: string\n image?: string\n version: string\n tags: string[]\n capabilities: string[]\n supportedTasks: string[]\n communicationProtocol: 'mcp' | 'a2a'\n authenticationMethod: 'ecdsa'\n pricing: AgentPricing\n\n // ── Private (AES-256-GCM encrypted, stored at encryptedPayloadCid) ──────\n prompt: string\n skills: SkillDef[]\n mcp: McpConnection\n}\n\n/** Subset of AgentPayload that is publicly visible */\nexport type AgentPublicPayload = Omit<\n AgentPayload,\n 'prompt' | 'skills' | 'mcp'\n>\n\n/** Fields that must be encrypted before IPFS upload */\nexport type AgentPrivatePayload = Pick<\n AgentPayload,\n 'prompt' | 'skills' | 'mcp'\n>\n\n// ── Encrypted Payload (IPFS wire format) ───────────────────────────────────\n\nexport interface EncryptedPayload {\n encrypted: true\n algorithm: 'AES-256-GCM'\n /** base64(iv + ciphertext + authTag) */\n data: string\n}\n\n// ── On-Chain Metadata (stored in ERC-721 tokenURI attributes) ─────────────\n\nexport interface OnChainAgentMetadata {\n tokenURI: string\n attributes: {\n name: string\n description: string\n /** CID of the AES-256-GCM encrypted payload on IPFS */\n encryptedPayloadCid: string\n /** ECIES-encrypted AES key (secp256k1, hex string) */\n eciesEncryptedKey: string\n /** CID of the public metadata on IPFS */\n publicPayloadCid: string\n capabilities: string[]\n skills: string[]\n mcpEndpoint: string\n version: string\n tags: string[]\n pricingType: PricingType\n pricingAmount: string\n }\n}\n\n// ── Agent Registry ─────────────────────────────────────────────────────────\n\nexport interface RegisteredAgent {\n /** ERC-721 token ID (= agentId) */\n agentId: number\n /** Owner wallet address */\n owner: string\n /** Creator wallet address */\n creator: string\n /** Full on-chain metadata */\n metadata: OnChainAgentMetadata\n /** Block number where agent was registered */\n registeredAt: number\n /** IPFS CID of the full public payload (resolved from tokenURI) */\n publicPayloadCid: string\n}\n\n// ── Agent Search ───────────────────────────────────────────────────────────\n\nexport interface AgentSearchQuery {\n keyword?: string\n capabilities?: string[]\n tags?: string[]\n pricingType?: PricingType\n maxPrice?: string\n owner?: string\n sortBy?: 'latest' | 'reputation' | 'price_asc' | 'price_desc'\n page?: number\n pageSize?: number\n}\n\nexport interface AgentSearchResult {\n agents: RegisteredAgent[]\n total: number\n page: number\n pageSize: number\n}\n\n// ── Subscription ───────────────────────────────────────────────────────────\n\nexport type SubscriptionStatus = 'active' | 'expired' | 'cancelled' | 'pending'\n\nexport interface AgentSubscription {\n subscriptionId: number\n subscriber: string\n agentId: number\n status: SubscriptionStatus\n startedAt: number\n expiresAt: number\n period: string\n}\n\n// ── A2A Protocol ───────────────────────────────────────────────────────────\n\nexport type A2ATaskStatus = 'created' | 'accepted' | 'in_progress' | 'completed' | 'failed'\n\nexport interface A2AAgentCard {\n agentId: number\n name: string\n capabilities: string[]\n supportedTasks: string[]\n /** MCP endpoint URL for direct agent-to-agent communication */\n endpoint: string\n /** Public key for ECDSA authentication */\n publicKey: string\n}\n\nexport interface A2ATask {\n taskId: number\n /** Agent that created the task */\n creator: string\n /** Target agent to execute the task */\n targetAgentId: number\n /** Task type (must be in target's supportedTasks) */\n taskType: string\n /** JSON input payload */\n input: string\n status: A2ATaskStatus\n result?: string\n createdAt: number\n completedAt?: number\n}\n\n// ── Reputation ─────────────────────────────────────────────────────────────\n\nexport interface AgentReputation {\n agentId: number\n averageRating: number\n totalRatings: number\n reviews: AgentReview[]\n}\n\nexport interface AgentReview {\n reviewer: string\n rating: number // 1-5\n comment: string\n timestamp: number\n}\n\n// ── AgentX Client Configuration ────────────────────────────────────────────\n\nexport interface AgentXConfig {\n /** Chain ID (e.g. 11155111 for Sepolia) */\n chainId: number\n /** RPC endpoint override (uses viem's default if omitted) */\n rpcUrl?: string\n /** Contract addresses for the current chain */\n contracts: AgentXContracts\n /** IPFS gateway URLs (ordered by priority) */\n ipfsGateways: string[]\n /** Default IPFS pinning service */\n pinningService?: 'pinata'\n pinataJwt?: string\n}\n\nexport interface AgentXContracts {\n identityRegistry: `0x${string}`\n subscriptionManager: `0x${string}`\n paymentGateway: `0x${string}`\n a2aProtocolRegistry: `0x${string}`\n reputationRegistry: `0x${string}`\n configurationRegistry: `0x${string}`\n}\n\n// ── Agent Packing / Unpacking Result ───────────────────────────────────────\n\nexport interface PackResult {\n /** CID of AES-256-GCM encrypted payload on IPFS */\n encryptedCid: string\n /** CID of public metadata on IPFS */\n publicCid: string\n /** Raw AES key (hex) — DO NOT share or upload this */\n aesKeyHex: string\n /** ECIES-encrypted AES key (hex), safe to store on-chain */\n eciesEncryptedKeyHex: string\n}\n\nexport interface UnpackResult {\n /** Decrypted AgentPayload */\n agent: AgentPayload\n /** CID where the encrypted payload was fetched from */\n encryptedCid: string\n /** CID of the public metadata */\n publicCid: string\n}\n\n// ── Error Types ────────────────────────────────────────────────────────────\n\nexport enum AgentXErrorCode {\n NOT_SUBSCRIBED = 'NOT_SUBSCRIBED',\n SUBSCRIPTION_EXPIRED = 'SUBSCRIPTION_EXPIRED',\n DECRYPTION_FAILED = 'DECRYPTION_FAILED',\n IPFS_FETCH_FAILED = 'IPFS_FETCH_FAILED',\n AGENT_NOT_FOUND = 'AGENT_NOT_FOUND',\n INVALID_SCHEMA = 'INVALID_SCHEMA',\n TX_FAILED = 'TX_FAILED',\n WALLET_NOT_CONNECTED = 'WALLET_NOT_CONNECTED',\n}\n\nexport class AgentXError extends Error {\n code: AgentXErrorCode\n /** If NOT_SUBSCRIBED, carry enough info for wallet/X402 auto-payment */\n paymentInfo?: SubscriptionRequired\n constructor(code: AgentXErrorCode, message: string) {\n super(message)\n this.code = code\n this.name = 'AgentXError'\n }\n}\n\n/**\n * Structured info for wallet/X402 auto-subscription.\n * Thrown by AgentRunner.useAgent() when the user/Agent has no\n * active subscription.\n */\nexport interface SubscriptionRequired {\n agentId: number\n /** Plan IDs available for this Agent (on-chain query) */\n plans?: { planId: number; price: bigint; period: string; payToken: string; trialDays: number }[]\n}\n","// ---------------------------------------------------------------------------\n// @agentx/sdk — Crypto Engine\n// ---------------------------------------------------------------------------\n// AES-256-GCM for content encryption (NIST standard, same wire format as\n// aihunter-saas for interop). ECIES (secp256k1) for key wrapping.\n//\n// Wire format (AES-256-GCM):\n// base64( IV[12] || ciphertext || authTag[16] )\n//\n// ECIES wire format (compatible with eciesjs):\n// hex( ephemeralPub[33] || IV[16] || ciphertext || MAC[32] )\n//\n// Pure JS — works in browser, Node, edge. No native deps except @noble/*.\n// ---------------------------------------------------------------------------\n\nimport { gcm } from '@noble/ciphers/aes.js'\nimport { secp256k1 } from '@noble/curves/secp256k1.js'\nimport { sha256 } from '@noble/hashes/sha2.js'\nimport { hkdf } from '@noble/hashes/hkdf.js'\nimport { hmac } from '@noble/hashes/hmac.js'\nimport { bytesToHex, hexToBytes } from '@noble/ciphers/utils.js'\n\n// ── randomBytes implementation (cross-runtime: browser / Node) ────────────\n\nexport function randomBytes(length: number): Uint8Array {\n // browser: crypto.getRandomValues\n if (typeof crypto !== 'undefined' && crypto.getRandomValues) {\n const buf = new Uint8Array(length)\n crypto.getRandomValues(buf)\n return buf\n }\n // Node: crypto.randomBytes\n // eslint-disable-next-line @typescript-eslint/no-require-imports\n const nodeCrypto = require('crypto')\n return new Uint8Array(nodeCrypto.randomBytes(length))\n}\n\nimport type { EncryptedPayload, AgentPrivatePayload } from './types'\nimport type { PackResult } from './types'\n\n// ── Re-exports for convenience ─────────────────────────────────────────────\n\nexport { bytesToHex, hexToBytes }\n\n// ── Constants ──────────────────────────────────────────────────────────────\n\nconst AES_KEY_SIZE = 32\nconst IV_SIZE = 12 // GCM recommended\nconst TAG_SIZE = 16 // GCM auth tag\n\n// ── Base64 helpers (cross-runtime) ─────────────────────────────────────────\n\nfunction toBase64(bytes: Uint8Array): string {\n // Works in browser (btoa + binary) and Node (Buffer)\n if (typeof Buffer !== 'undefined') return Buffer.from(bytes).toString('base64')\n let binary = ''\n for (let i = 0; i < bytes.length; i++) binary += String.fromCharCode(bytes[i]!)\n return btoa(binary)\n}\n\nfunction fromBase64(b64: string): Uint8Array {\n if (typeof Buffer !== 'undefined') return new Uint8Array(Buffer.from(b64, 'base64'))\n const binary = atob(b64)\n const bytes = new Uint8Array(binary.length)\n for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i)\n return bytes\n}\n\n// ── AES-256-GCM ────────────────────────────────────────────────────────────\n\n/**\n * Encrypt with AES-256-GCM.\n * Wire format (same as aihunter-saas): base64( IV[12] || ciphertext || authTag[16] )\n */\nexport function aesEncrypt(plaintext: string, keyHex: string): string {\n const key = hexToBytes(keyHex)\n const iv = randomBytes(IV_SIZE)\n const plainBytes = new TextEncoder().encode(plaintext)\n\n const cipher = gcm(key, iv)\n const encrypted = cipher.encrypt(plainBytes)\n // noble gcm.encrypt returns: ciphertext || authTag(16)\n const ciphertext = encrypted.subarray(0, -TAG_SIZE)\n const authTag = encrypted.subarray(-TAG_SIZE)\n\n // Pack: IV || ciphertext || authTag\n const combined = new Uint8Array(IV_SIZE + ciphertext.length + TAG_SIZE)\n combined.set(iv, 0)\n combined.set(ciphertext, IV_SIZE)\n combined.set(authTag, IV_SIZE + ciphertext.length)\n\n return toBase64(combined)\n}\n\n/**\n * Decrypt AES-256-GCM (same wire format as aihunter-saas).\n */\nexport function aesDecrypt(encryptedBase64: string, keyHex: string): string {\n const key = hexToBytes(keyHex)\n const combined = fromBase64(encryptedBase64)\n\n const iv = combined.subarray(0, IV_SIZE)\n const ciphertext = combined.subarray(IV_SIZE, -TAG_SIZE)\n const authTag = combined.subarray(-TAG_SIZE)\n\n const cipher = gcm(key, iv)\n // noble decrypt expects: ciphertext || authTag\n const ciphertextWithTag = new Uint8Array(ciphertext.length + TAG_SIZE)\n ciphertextWithTag.set(ciphertext, 0)\n ciphertextWithTag.set(authTag, ciphertext.length)\n\n const decrypted = cipher.decrypt(ciphertextWithTag)\n return new TextDecoder().decode(decrypted)\n}\n\n/**\n * Generate a cryptographically random AES-256 key (hex, 64 chars).\n */\nexport function generateAesKey(): string {\n return bytesToHex(randomBytes(AES_KEY_SIZE))\n}\n\n// ── ECIES (secp256k1) ──────────────────────────────────────────────────────\n//\n// eciesjs-compatible wire format:\n// ephemeralPub(33B compressed) || IV(16B) || ciphertext || MAC(32B)\n// Encoding: hex\n//\n// HKDF(SHA-256) derives AES key + HMAC key from ECDH shared secret.\n// ---------------------------------------------------------------------------\n\nfunction eciesEncode(\n ephemeralPub: Uint8Array,\n iv: Uint8Array,\n ciphertext: Uint8Array,\n mac: Uint8Array\n): string {\n const out = new Uint8Array(33 + 16 + ciphertext.length + 32)\n out.set(ephemeralPub, 0)\n out.set(iv, 33)\n out.set(ciphertext, 33 + 16)\n out.set(mac, 33 + 16 + ciphertext.length)\n return bytesToHex(out)\n}\n\nfunction eciesDecode(dataHex: string): {\n ephemeralPub: Uint8Array\n iv: Uint8Array\n ciphertext: Uint8Array\n mac: Uint8Array\n} {\n const d = hexToBytes(dataHex)\n return {\n ephemeralPub: d.subarray(0, 33),\n iv: d.subarray(33, 49),\n ciphertext: d.subarray(49, -32),\n mac: d.subarray(-32),\n }\n}\n\n// Simple AES-256-CTR implementation on top of @noble/ciphers AES core\nfunction aesCtrEncrypt(key: Uint8Array, ctrBytes: Uint8Array, data: Uint8Array): Uint8Array {\n const blockSize = 16\n const cipher = gcm(key, ctrBytes) // GCM internally handles CTR\n // Use noble's CTR approach: encrypt the plaintext directly with the derived stream\n // noble uses AES-CTR internally for GCM; simpler: implement CTR with AES-ECB\n const result = new Uint8Array(data.length)\n const counter = new Uint8Array(blockSize)\n counter.set(ctrBytes)\n for (let i = 0; i < data.length; i += blockSize) {\n const keystream = gcm(key, counter).encrypt(new Uint8Array(blockSize))\n for (let j = 0; j < blockSize && i + j < data.length; j++) {\n result[i + j] = keystream[j]! ^ data[i + j]!\n }\n // Increment counter (big-endian)\n for (let j = blockSize - 1; j >= 0; j--) {\n const val = counter[j]\n if (val !== undefined) {\n counter[j] = (val + 1) & 0xff\n if (counter[j] !== 0) break\n }\n }\n }\n return result\n}\n\n/**\n * Encrypt data with recipient's secp256k1 public key (ECIES).\n *\n * @param dataHex The data to encrypt (hex, e.g. AES key)\n * @param publicKey Recipient's public key (hex, 04-prefixed uncompressed or 02/03 compressed)\n */\nexport function eciesEncrypt(dataHex: string, publicKey: string): string {\n // 1. Ephemeral keypair\n const ephPriv = randomBytes(32)\n const ephPub = secp256k1.getPublicKey(ephPriv, true) // 33B compressed\n\n // 2. Parse recipient public key\n let recipientPub: Uint8Array\n if (publicKey.startsWith('04') && publicKey.length === 130) {\n recipientPub = hexToBytes(publicKey)\n } else if (publicKey.startsWith('02') || publicKey.startsWith('03')) {\n recipientPub = hexToBytes(publicKey)\n } else {\n throw new Error('Invalid public key format: expected hex with 02/03/04 prefix')\n }\n\n // 3. ECDH\n const shared = secp256k1.getSharedSecret(ephPriv, recipientPub)\n const sharedX = shared.subarray(1, 33) // x-coordinate only\n const sharedKey = sha256(sharedX)\n\n // 4. HKDF: encKey(32) || macKey(32)\n const hkdfOut = hkdf(sha256, sharedKey, undefined, undefined, 64)\n const encKey = hkdfOut.subarray(0, 32)\n const macKey = hkdfOut.subarray(32, 64)\n\n // 5. AES-256-CTR encrypt\n const iv = randomBytes(16)\n const plaintext = hexToBytes(dataHex)\n const ciphertext = aesCtrEncrypt(encKey, iv, plaintext)\n\n // 6. HMAC: MAC(ephemeralPub || IV || ciphertext)\n const macInput = new Uint8Array(33 + 16 + ciphertext.length)\n macInput.set(ephPub, 0)\n macInput.set(iv, 33)\n macInput.set(ciphertext, 33 + 16)\n const mac = hmac(sha256, macKey, macInput)\n\n return eciesEncode(ephPub, iv, ciphertext, mac)\n}\n\n/**\n * Decrypt ECIES ciphertext with recipient's secp256k1 private key.\n */\nexport function eciesDecrypt(dataHex: string, privateKey: string): string {\n const { ephemeralPub, iv, ciphertext, mac } = eciesDecode(dataHex)\n\n // 1. ECDH\n const privBytes = hexToBytes(privateKey)\n const shared = secp256k1.getSharedSecret(privBytes, ephemeralPub)\n const sharedX = shared.subarray(1, 33)\n const sharedKey = sha256(sharedX)\n\n // 2. HKDF\n const hkdfOut = hkdf(sha256, sharedKey, undefined, undefined, 64)\n const encKey = hkdfOut.subarray(0, 32)\n const macKey = hkdfOut.subarray(32, 64)\n\n // 3. Verify MAC\n const macInput = new Uint8Array(33 + 16 + ciphertext.length)\n macInput.set(ephemeralPub, 0)\n macInput.set(iv, 33)\n macInput.set(ciphertext, 33 + 16)\n const expectedMac = hmac(sha256, macKey, macInput)\n if (!constantTimeEqual(mac, expectedMac)) {\n throw new Error('ECIES decryption failed: MAC mismatch')\n }\n\n // 4. Decrypt\n const plaintext = aesCtrEncrypt(encKey, iv, ciphertext) // CTR encrypt = decrypt\n return bytesToHex(plaintext)\n}\n\nfunction constantTimeEqual(a: Uint8Array, b: Uint8Array): boolean {\n if (a.length !== b.length) return false\n let diff = 0\n for (let i = 0; i < a.length; i++) diff |= a[i]! ^ b[i]!\n return diff === 0\n}\n\n// ── High-Level: Agent Pack / Unpack ────────────────────────────────────────\n\n/**\n * Encrypt an Agent's private payload with AES-256-GCM.\n */\nexport function encryptPayload(\n payload: AgentPrivatePayload,\n keyHex?: string\n): EncryptedPayload {\n const key = keyHex ?? generateAesKey()\n return {\n encrypted: true,\n algorithm: 'AES-256-GCM',\n data: aesEncrypt(JSON.stringify(payload), key),\n }\n}\n\n/**\n * Decrypt an EncryptedPayload.\n */\nexport function decryptPayload(\n encrypted: EncryptedPayload,\n keyHex: string\n): AgentPrivatePayload {\n if (encrypted.algorithm !== 'AES-256-GCM') {\n throw new Error(`Unsupported algorithm: ${encrypted.algorithm}`)\n }\n return JSON.parse(aesDecrypt(encrypted.data, keyHex)) as AgentPrivatePayload\n}\n\n/**\n * Pack an AgentPayload for publishing.\n * 1. Split public/private\n * 2. AES-256-GCM encrypt private part\n * 3. ECIES wrap AES key with creator's public key\n */\nexport function packAgentForPublish(\n agent: import('./types').AgentPayload,\n publicKey: string,\n aesKeyHex?: string\n): PackResult {\n const key = aesKeyHex ?? generateAesKey()\n\n const eciesEncryptedKeyHex = eciesEncrypt(key, publicKey)\n\n return {\n encryptedCid: '', // filled after IPFS upload\n publicCid: '', // filled after IPFS upload\n aesKeyHex: key,\n eciesEncryptedKeyHex,\n }\n}\n\n/**\n * Unpack an Agent:\n * 1. ECIES decrypt the AES key (private key)\n * 2. AES-256-GCM decrypt the payload\n */\nexport function unpackAgent(\n encryptedPayload: EncryptedPayload,\n eciesEncryptedKey: string,\n privateKey: string\n): AgentPrivatePayload {\n const aesKeyHex = eciesDecrypt(eciesEncryptedKey, privateKey)\n return decryptPayload(encryptedPayload, aesKeyHex)\n}\n\n// ── Key Pair Utilities ─────────────────────────────────────────────────────\n\n/**\n * Generate a secp256k1 keypair compatible with Ethereum wallets.\n */\nexport function generateKeyPair(): { privateKey: string; publicKey: string } {\n const priv = randomBytes(32)\n const pub = secp256k1.getPublicKey(priv, false) // uncompressed 04-prefixed\n return { privateKey: bytesToHex(priv), publicKey: bytesToHex(pub) }\n}\n\n/**\n * Derive public key from private key (hex).\n */\nexport function getPublicKey(privateKey: string): string {\n return bytesToHex(secp256k1.getPublicKey(hexToBytes(privateKey), false))\n}\n"],"mappings":";;;;;;;;AAmVO,IAAK,kBAAL,kBAAKA,qBAAL;AACL,EAAAA,iBAAA,oBAAiB;AACjB,EAAAA,iBAAA,0BAAuB;AACvB,EAAAA,iBAAA,uBAAoB;AACpB,EAAAA,iBAAA,uBAAoB;AACpB,EAAAA,iBAAA,qBAAkB;AAClB,EAAAA,iBAAA,oBAAiB;AACjB,EAAAA,iBAAA,eAAY;AACZ,EAAAA,iBAAA,0BAAuB;AARb,SAAAA;AAAA,GAAA;AAWL,IAAM,cAAN,cAA0B,MAAM;AAAA,EACrC;AAAA;AAAA,EAEA;AAAA,EACA,YAAY,MAAuB,SAAiB;AAClD,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,OAAO;AAAA,EACd;AACF;;;ACxVA,SAAS,WAAW;AACpB,SAAS,iBAAiB;AAC1B,SAAS,cAAc;AACvB,SAAS,YAAY;AACrB,SAAS,YAAY;AACrB,SAAS,YAAY,kBAAkB;AAIhC,SAAS,YAAY,QAA4B;AAEtD,MAAI,OAAO,WAAW,eAAe,OAAO,iBAAiB;AAC3D,UAAM,MAAM,IAAI,WAAW,MAAM;AACjC,WAAO,gBAAgB,GAAG;AAC1B,WAAO;AAAA,EACT;AAGA,QAAM,aAAa,UAAQ,QAAQ;AACnC,SAAO,IAAI,WAAW,WAAW,YAAY,MAAM,CAAC;AACtD;AAWA,IAAM,eAAe;AACrB,IAAM,UAAU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d,WACA,QACqB;AACrB,MAAI,UAAU,cAAc,eAAe;AACzC,UAAM,IAAI,MAAM,0BAA0B,UAAU,SAAS,EAAE;AAAA,EACjE;AACA,SAAO,KAAK,MAAM,WAAW,UAAU,MAAM,MAAM,CAAC;AACtD;AAQO,SAAS,oBACd,OACA,WACA,WACY;AACZ,QAAM,MAAM,aAAa,eAAe;AAExC,QAAM,uBAAuB,aAAa,KAAK,SAAS;AAExD,SAAO;AAAA,IACL,cAAc;AAAA;AAAA,IACd,WAAW;AAAA;AAAA,IACX,WAAW;AAAA,IACX;AAAA,EACF;AACF;AAOO,SAAS,YACd,kBACA,mBACA,YACqB;AACrB,QAAM,YAAY,aAAa,mBAAmB,UAAU;AAC5D,SAAO,eAAe,kBAAkB,SAAS;AACnD;AAOO,SAAS,kBAA6D;AAC3E,QAAM,OAAO,YAAY,EAAE;AAC3B,QAAM,MAAM,UAAU,aAAa,MAAM,KAAK;AAC9C,SAAO,EAAE,YAAY,WAAW,IAAI,GAAG,WAAW,WAAW,GAAG,EAAE;AACpE;AAKO,SAAS,aAAa,YAA4B;AACvD,SAAO,WAAW,UAAU,aAAa,WAAW,UAAU,GAAG,KAAK,CAAC;AACzE;","names":["AgentXErrorCode"]}
|
|
@@ -1,7 +1,46 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import { E as EncryptedPayload, g as AgentPayload, P as PackResult } from './types-2aHUvS4M.js';
|
|
2
|
+
import { Address, PublicClient, WalletClient, Hash } from 'viem';
|
|
3
|
+
|
|
4
|
+
interface IPFSFetcherConfig {
|
|
5
|
+
/** Primary IPFS gateway (default: ipfs.io) */
|
|
6
|
+
gateway?: string;
|
|
7
|
+
/** Fallback gateways in order of preference */
|
|
8
|
+
fallbackGateways?: string[];
|
|
9
|
+
/** Request timeout in ms (default: 10_000) */
|
|
10
|
+
timeoutMs?: number;
|
|
11
|
+
/** Max cached entries (LRU-like eviction, default: 200) */
|
|
12
|
+
maxCache?: number;
|
|
13
|
+
}
|
|
14
|
+
declare class IPFSFetcher {
|
|
15
|
+
private gateway;
|
|
16
|
+
private fallbackGateways;
|
|
17
|
+
private timeoutMs;
|
|
18
|
+
private cache;
|
|
19
|
+
private maxCache;
|
|
20
|
+
private pending;
|
|
21
|
+
private failed;
|
|
22
|
+
constructor(config?: IPFSFetcherConfig);
|
|
23
|
+
/** Fetch JSON from a single IPFS CID. */
|
|
24
|
+
fetchJSON<T = unknown>(cid: string): Promise<T>;
|
|
25
|
+
/** Fetch encrypted agent payload (validates algorithm). */
|
|
26
|
+
fetchEncryptedPayload(cid: string): Promise<EncryptedPayload>;
|
|
27
|
+
/** Batch fetch multiple CIDs with concurrency control. */
|
|
28
|
+
fetchBatch<T = unknown>(cids: string[], concurrency?: number): Promise<Map<string, T>>;
|
|
29
|
+
/** Check if a string looks like a valid IPFS CID. */
|
|
30
|
+
isValidCID(cid: string): boolean;
|
|
31
|
+
/** Clear cache (optionally for a specific CID). */
|
|
32
|
+
clearCache(cid?: string): void;
|
|
33
|
+
/** Number of cached entries. */
|
|
34
|
+
get cacheSize(): number;
|
|
35
|
+
private _doFetch;
|
|
36
|
+
private _fetchFrom;
|
|
37
|
+
private _cacheSet;
|
|
38
|
+
}
|
|
39
|
+
/** Singleton-friendly default instance. */
|
|
40
|
+
declare const defaultIPFSFetcher: IPFSFetcher;
|
|
41
|
+
|
|
3
42
|
/** Minimal on-chain reader interface — implement with viem. */
|
|
4
|
-
|
|
43
|
+
interface OnChainReader {
|
|
5
44
|
/** Read tokenURI from IdentityRegistry by tokenId. */
|
|
6
45
|
getTokenURI(agentId: number): Promise<string>;
|
|
7
46
|
/** Get agent metadata attributes (returned as key-value pairs). */
|
|
@@ -10,7 +49,7 @@ export interface OnChainReader {
|
|
|
10
49
|
hasActiveSubscription(address: string, agentId: number): Promise<boolean>;
|
|
11
50
|
}
|
|
12
51
|
/** Minimal wallet signer interface — implement with wagmi/viem. */
|
|
13
|
-
|
|
52
|
+
interface WalletSigner {
|
|
14
53
|
/** Sign a message (for authentication to MCP servers). */
|
|
15
54
|
signMessage(message: string): Promise<string>;
|
|
16
55
|
/** Get the current wallet address. */
|
|
@@ -18,7 +57,7 @@ export interface WalletSigner {
|
|
|
18
57
|
/** Get the wallet's ECDSA private key (required for ECIES decryption). */
|
|
19
58
|
getPrivateKey?(): Promise<string>;
|
|
20
59
|
}
|
|
21
|
-
|
|
60
|
+
interface AgentRunnerConfig {
|
|
22
61
|
/** On-chain data reader (injected from viem/wagmi). */
|
|
23
62
|
reader: OnChainReader;
|
|
24
63
|
/** Wallet signer (injected from wagmi). */
|
|
@@ -28,7 +67,7 @@ export interface AgentRunnerConfig {
|
|
|
28
67
|
/** IPFS gateway list (overrides IPFSFetcher defaults). */
|
|
29
68
|
ipfsGateways?: string[];
|
|
30
69
|
}
|
|
31
|
-
|
|
70
|
+
interface AgentRunContext {
|
|
32
71
|
/** Agent NFT token ID */
|
|
33
72
|
agentId: number;
|
|
34
73
|
/** System prompt — inject into LLM conversation */
|
|
@@ -44,7 +83,7 @@ export interface AgentRunContext {
|
|
|
44
83
|
/** Subscription expiry timestamp (0 = unknown) */
|
|
45
84
|
subscriptionExpiry: number;
|
|
46
85
|
}
|
|
47
|
-
|
|
86
|
+
interface RunnableSkill {
|
|
48
87
|
name: string;
|
|
49
88
|
description: string;
|
|
50
89
|
inputSchema: Record<string, unknown>;
|
|
@@ -66,7 +105,7 @@ export interface RunnableSkill {
|
|
|
66
105
|
* The calling LLM receives the sub-Agent's prompt and skills
|
|
67
106
|
* and can inject them into the conversation.
|
|
68
107
|
*/
|
|
69
|
-
|
|
108
|
+
interface A2ASkillResult {
|
|
70
109
|
/** On-chain Agent ID that was delegated to */
|
|
71
110
|
agentId: number;
|
|
72
111
|
/** Sub-Agent's decrypted system prompt */
|
|
@@ -80,7 +119,7 @@ export interface A2ASkillResult {
|
|
|
80
119
|
/** The original input passed by the caller */
|
|
81
120
|
callerInput: Record<string, unknown>;
|
|
82
121
|
}
|
|
83
|
-
|
|
122
|
+
declare class AgentRunner {
|
|
84
123
|
private reader;
|
|
85
124
|
private wallet;
|
|
86
125
|
private ipfs;
|
|
@@ -121,4 +160,49 @@ export declare class AgentRunner {
|
|
|
121
160
|
private _executeA2ASkill;
|
|
122
161
|
private _getPrivateKey;
|
|
123
162
|
}
|
|
124
|
-
|
|
163
|
+
|
|
164
|
+
interface ChainConfig {
|
|
165
|
+
chainId: number;
|
|
166
|
+
contracts: {
|
|
167
|
+
identityRegistry: Address;
|
|
168
|
+
subscriptionManager: Address;
|
|
169
|
+
paymentGateway: Address;
|
|
170
|
+
a2aProtocolRegistry: Address;
|
|
171
|
+
reputationRegistry: Address;
|
|
172
|
+
configurationRegistry: Address;
|
|
173
|
+
};
|
|
174
|
+
ipfsGateways: string[];
|
|
175
|
+
rpcUrl?: string;
|
|
176
|
+
}
|
|
177
|
+
declare const KNOWN_CHAINS: Record<number, ChainConfig>;
|
|
178
|
+
interface ConfigRegistryOpts {
|
|
179
|
+
contractAddress: Address;
|
|
180
|
+
publicClient: PublicClient;
|
|
181
|
+
walletClient: WalletClient;
|
|
182
|
+
}
|
|
183
|
+
declare class ConfigurationRegistry {
|
|
184
|
+
private address;
|
|
185
|
+
private publicClient;
|
|
186
|
+
private walletClient;
|
|
187
|
+
constructor(opts: ConfigRegistryOpts);
|
|
188
|
+
private get account();
|
|
189
|
+
set(key: string, value: string): Promise<Hash>;
|
|
190
|
+
get(key: string): Promise<string>;
|
|
191
|
+
getAll(): Promise<Record<string, string>>;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
interface UseAgentRunnerConfig {
|
|
195
|
+
agentId: number;
|
|
196
|
+
chainConfig?: ChainConfig;
|
|
197
|
+
ipfsGateways?: string[];
|
|
198
|
+
}
|
|
199
|
+
interface UseAgentRunnerResult {
|
|
200
|
+
ctx: AgentRunContext | null;
|
|
201
|
+
isLoading: boolean;
|
|
202
|
+
error: Error | null;
|
|
203
|
+
/** Re-trigger the load (e.g. after connecting wallet or subscribing) */
|
|
204
|
+
refetch: () => void;
|
|
205
|
+
}
|
|
206
|
+
declare function useAgentRunner(config: UseAgentRunnerConfig): UseAgentRunnerResult;
|
|
207
|
+
|
|
208
|
+
export { type A2ASkillResult as A, type ChainConfig as C, IPFSFetcher as I, KNOWN_CHAINS as K, type OnChainReader as O, type RunnableSkill as R, type UseAgentRunnerConfig as U, type WalletSigner as W, type AgentRunContext as a, AgentRunner as b, type AgentRunnerConfig as c, type ConfigRegistryOpts as d, ConfigurationRegistry as e, type IPFSFetcherConfig as f, type UseAgentRunnerResult as g, defaultIPFSFetcher as h, useAgentRunner as u };
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { E as EncryptedPayload, g as AgentPayload, P as PackResult } from './types-2aHUvS4M.mjs';
|
|
2
|
+
import { Address, PublicClient, WalletClient, Hash } from 'viem';
|
|
3
|
+
|
|
4
|
+
interface IPFSFetcherConfig {
|
|
5
|
+
/** Primary IPFS gateway (default: ipfs.io) */
|
|
6
|
+
gateway?: string;
|
|
7
|
+
/** Fallback gateways in order of preference */
|
|
8
|
+
fallbackGateways?: string[];
|
|
9
|
+
/** Request timeout in ms (default: 10_000) */
|
|
10
|
+
timeoutMs?: number;
|
|
11
|
+
/** Max cached entries (LRU-like eviction, default: 200) */
|
|
12
|
+
maxCache?: number;
|
|
13
|
+
}
|
|
14
|
+
declare class IPFSFetcher {
|
|
15
|
+
private gateway;
|
|
16
|
+
private fallbackGateways;
|
|
17
|
+
private timeoutMs;
|
|
18
|
+
private cache;
|
|
19
|
+
private maxCache;
|
|
20
|
+
private pending;
|
|
21
|
+
private failed;
|
|
22
|
+
constructor(config?: IPFSFetcherConfig);
|
|
23
|
+
/** Fetch JSON from a single IPFS CID. */
|
|
24
|
+
fetchJSON<T = unknown>(cid: string): Promise<T>;
|
|
25
|
+
/** Fetch encrypted agent payload (validates algorithm). */
|
|
26
|
+
fetchEncryptedPayload(cid: string): Promise<EncryptedPayload>;
|
|
27
|
+
/** Batch fetch multiple CIDs with concurrency control. */
|
|
28
|
+
fetchBatch<T = unknown>(cids: string[], concurrency?: number): Promise<Map<string, T>>;
|
|
29
|
+
/** Check if a string looks like a valid IPFS CID. */
|
|
30
|
+
isValidCID(cid: string): boolean;
|
|
31
|
+
/** Clear cache (optionally for a specific CID). */
|
|
32
|
+
clearCache(cid?: string): void;
|
|
33
|
+
/** Number of cached entries. */
|
|
34
|
+
get cacheSize(): number;
|
|
35
|
+
private _doFetch;
|
|
36
|
+
private _fetchFrom;
|
|
37
|
+
private _cacheSet;
|
|
38
|
+
}
|
|
39
|
+
/** Singleton-friendly default instance. */
|
|
40
|
+
declare const defaultIPFSFetcher: IPFSFetcher;
|
|
41
|
+
|
|
42
|
+
/** Minimal on-chain reader interface — implement with viem. */
|
|
43
|
+
interface OnChainReader {
|
|
44
|
+
/** Read tokenURI from IdentityRegistry by tokenId. */
|
|
45
|
+
getTokenURI(agentId: number): Promise<string>;
|
|
46
|
+
/** Get agent metadata attributes (returned as key-value pairs). */
|
|
47
|
+
getAttributes(agentId: number): Promise<Record<string, string>>;
|
|
48
|
+
/** Check if `address` has an active subscription for `agentId`. */
|
|
49
|
+
hasActiveSubscription(address: string, agentId: number): Promise<boolean>;
|
|
50
|
+
}
|
|
51
|
+
/** Minimal wallet signer interface — implement with wagmi/viem. */
|
|
52
|
+
interface WalletSigner {
|
|
53
|
+
/** Sign a message (for authentication to MCP servers). */
|
|
54
|
+
signMessage(message: string): Promise<string>;
|
|
55
|
+
/** Get the current wallet address. */
|
|
56
|
+
getAddress(): Promise<string>;
|
|
57
|
+
/** Get the wallet's ECDSA private key (required for ECIES decryption). */
|
|
58
|
+
getPrivateKey?(): Promise<string>;
|
|
59
|
+
}
|
|
60
|
+
interface AgentRunnerConfig {
|
|
61
|
+
/** On-chain data reader (injected from viem/wagmi). */
|
|
62
|
+
reader: OnChainReader;
|
|
63
|
+
/** Wallet signer (injected from wagmi). */
|
|
64
|
+
wallet: WalletSigner;
|
|
65
|
+
/** IPFS fetcher instance (creates default if omitted). */
|
|
66
|
+
ipfsFetcher?: IPFSFetcher;
|
|
67
|
+
/** IPFS gateway list (overrides IPFSFetcher defaults). */
|
|
68
|
+
ipfsGateways?: string[];
|
|
69
|
+
}
|
|
70
|
+
interface AgentRunContext {
|
|
71
|
+
/** Agent NFT token ID */
|
|
72
|
+
agentId: number;
|
|
73
|
+
/** System prompt — inject into LLM conversation */
|
|
74
|
+
prompt: string;
|
|
75
|
+
/** All skills with execution metadata */
|
|
76
|
+
skills: RunnableSkill[];
|
|
77
|
+
/** MCP connection info */
|
|
78
|
+
mcp: {
|
|
79
|
+
type: string;
|
|
80
|
+
url?: string;
|
|
81
|
+
toolFilter?: string[];
|
|
82
|
+
};
|
|
83
|
+
/** Subscription expiry timestamp (0 = unknown) */
|
|
84
|
+
subscriptionExpiry: number;
|
|
85
|
+
}
|
|
86
|
+
interface RunnableSkill {
|
|
87
|
+
name: string;
|
|
88
|
+
description: string;
|
|
89
|
+
inputSchema: Record<string, unknown>;
|
|
90
|
+
outputSchema?: Record<string, unknown>;
|
|
91
|
+
/** Execution mode */
|
|
92
|
+
mode: 'open' | 'mcp' | 'a2a';
|
|
93
|
+
/** If mode='a2a', the on-chain Agent ID being delegated to */
|
|
94
|
+
a2aTargetAgentId?: number;
|
|
95
|
+
/**
|
|
96
|
+
* Execute this skill with the given input.
|
|
97
|
+
* - Open: runs locally (caller provides implementation)
|
|
98
|
+
* - MCP: POSTs to the publisher's MCP server
|
|
99
|
+
* - A2A: loads target Agent context (prompt+skills) via AgentRunner
|
|
100
|
+
*/
|
|
101
|
+
execute(input: Record<string, unknown>): Promise<unknown>;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Standard return type for A2A skill execution.
|
|
105
|
+
* The calling LLM receives the sub-Agent's prompt and skills
|
|
106
|
+
* and can inject them into the conversation.
|
|
107
|
+
*/
|
|
108
|
+
interface A2ASkillResult {
|
|
109
|
+
/** On-chain Agent ID that was delegated to */
|
|
110
|
+
agentId: number;
|
|
111
|
+
/** Sub-Agent's decrypted system prompt */
|
|
112
|
+
prompt: string;
|
|
113
|
+
/** Sub-Agent's skills (name + description + schema only, no execute) */
|
|
114
|
+
skills: {
|
|
115
|
+
name: string;
|
|
116
|
+
description: string;
|
|
117
|
+
inputSchema: Record<string, unknown>;
|
|
118
|
+
}[];
|
|
119
|
+
/** The original input passed by the caller */
|
|
120
|
+
callerInput: Record<string, unknown>;
|
|
121
|
+
}
|
|
122
|
+
declare class AgentRunner {
|
|
123
|
+
private reader;
|
|
124
|
+
private wallet;
|
|
125
|
+
private ipfs;
|
|
126
|
+
constructor(config: AgentRunnerConfig);
|
|
127
|
+
/**
|
|
128
|
+
* Load and decrypt an Agent, returning a run context ready to inject
|
|
129
|
+
* into any LLM conversation.
|
|
130
|
+
*
|
|
131
|
+
* Steps:
|
|
132
|
+
* 1. Verify on-chain subscription (frontend check)
|
|
133
|
+
* 2. Fetch metadata → get encryptedPayloadCid + eciesEncryptedKey
|
|
134
|
+
* 3. IPFS fetch encrypted payload
|
|
135
|
+
* 4. ECIES decrypt AES key (using wallet private key)
|
|
136
|
+
* 5. AES-256-GCM decrypt payload → { prompt, skills, mcp }
|
|
137
|
+
* 6. Build RunnableSkill wrappers (Open: local stub, Closed: MCP remote)
|
|
138
|
+
*/
|
|
139
|
+
useAgent(agentId: number): Promise<AgentRunContext>;
|
|
140
|
+
/**
|
|
141
|
+
* Pack an AgentPayload for publishing (encryption only, no IPFS upload).
|
|
142
|
+
* Caller is responsible for IPFS upload and on-chain registration.
|
|
143
|
+
*/
|
|
144
|
+
packForPublish(payload: AgentPayload, publicKey: string): PackResult;
|
|
145
|
+
/** Wrap a SkillDef into a RunnableSkill with execute(). */
|
|
146
|
+
private _wrapSkill;
|
|
147
|
+
/** Call a tool on the publisher's MCP server (Closed skill). */
|
|
148
|
+
private _executeMCPTool;
|
|
149
|
+
/**
|
|
150
|
+
* Execute an A2A skill — delegate to another AgentX Agent.
|
|
151
|
+
*
|
|
152
|
+
* Standard Interface:
|
|
153
|
+
* Input: { task, ...taskSpecificParams }
|
|
154
|
+
* Output: { agentId, prompt, skills[] }
|
|
155
|
+
*
|
|
156
|
+
* The caller (LLM) receives the sub-Agent's prompt + skill list.
|
|
157
|
+
* The LLM then decides how to use the sub-Agent — typically by
|
|
158
|
+
* injecting the sub-Agent's system prompt and calling its skills.
|
|
159
|
+
*/
|
|
160
|
+
private _executeA2ASkill;
|
|
161
|
+
private _getPrivateKey;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
interface ChainConfig {
|
|
165
|
+
chainId: number;
|
|
166
|
+
contracts: {
|
|
167
|
+
identityRegistry: Address;
|
|
168
|
+
subscriptionManager: Address;
|
|
169
|
+
paymentGateway: Address;
|
|
170
|
+
a2aProtocolRegistry: Address;
|
|
171
|
+
reputationRegistry: Address;
|
|
172
|
+
configurationRegistry: Address;
|
|
173
|
+
};
|
|
174
|
+
ipfsGateways: string[];
|
|
175
|
+
rpcUrl?: string;
|
|
176
|
+
}
|
|
177
|
+
declare const KNOWN_CHAINS: Record<number, ChainConfig>;
|
|
178
|
+
interface ConfigRegistryOpts {
|
|
179
|
+
contractAddress: Address;
|
|
180
|
+
publicClient: PublicClient;
|
|
181
|
+
walletClient: WalletClient;
|
|
182
|
+
}
|
|
183
|
+
declare class ConfigurationRegistry {
|
|
184
|
+
private address;
|
|
185
|
+
private publicClient;
|
|
186
|
+
private walletClient;
|
|
187
|
+
constructor(opts: ConfigRegistryOpts);
|
|
188
|
+
private get account();
|
|
189
|
+
set(key: string, value: string): Promise<Hash>;
|
|
190
|
+
get(key: string): Promise<string>;
|
|
191
|
+
getAll(): Promise<Record<string, string>>;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
interface UseAgentRunnerConfig {
|
|
195
|
+
agentId: number;
|
|
196
|
+
chainConfig?: ChainConfig;
|
|
197
|
+
ipfsGateways?: string[];
|
|
198
|
+
}
|
|
199
|
+
interface UseAgentRunnerResult {
|
|
200
|
+
ctx: AgentRunContext | null;
|
|
201
|
+
isLoading: boolean;
|
|
202
|
+
error: Error | null;
|
|
203
|
+
/** Re-trigger the load (e.g. after connecting wallet or subscribing) */
|
|
204
|
+
refetch: () => void;
|
|
205
|
+
}
|
|
206
|
+
declare function useAgentRunner(config: UseAgentRunnerConfig): UseAgentRunnerResult;
|
|
207
|
+
|
|
208
|
+
export { type A2ASkillResult as A, type ChainConfig as C, IPFSFetcher as I, KNOWN_CHAINS as K, type OnChainReader as O, type RunnableSkill as R, type UseAgentRunnerConfig as U, type WalletSigner as W, type AgentRunContext as a, AgentRunner as b, type AgentRunnerConfig as c, type ConfigRegistryOpts as d, ConfigurationRegistry as e, type IPFSFetcherConfig as f, type UseAgentRunnerResult as g, defaultIPFSFetcher as h, useAgentRunner as u };
|