@agentxv2/sdk 0.5.2 → 0.5.3
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/configuration/index.d.mts +31 -0
- package/dist/configuration/index.d.ts +31 -0
- package/dist/configuration/index.js +155 -0
- package/dist/configuration/index.js.map +1 -0
- package/dist/configuration/index.mjs +128 -0
- package/dist/configuration/index.mjs.map +1 -0
- package/dist/core.d.mts +64 -0
- package/dist/core.d.ts +64 -0
- package/dist/endpoint/index.d.mts +39 -0
- package/dist/endpoint/index.d.ts +39 -0
- package/dist/endpoint/index.js +193 -0
- package/dist/endpoint/index.js.map +1 -0
- package/dist/endpoint/index.mjs +166 -0
- package/dist/endpoint/index.mjs.map +1 -0
- package/dist/index-BlD1-fQt.d.mts +209 -0
- package/dist/index-DV-tFsBT.d.ts +209 -0
- package/dist/index.d.mts +271 -0
- package/dist/index.d.ts +271 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/react.d.mts +3 -0
- package/dist/react.d.ts +3 -0
- package/dist/types-2aHUvS4M.d.mts +297 -0
- package/dist/types-2aHUvS4M.d.ts +297 -0
- package/package.json +2 -2
- /package/dist/{core/index.js → core.js} +0 -0
- /package/dist/{core/index.js.map → core.js.map} +0 -0
- /package/dist/{core/index.mjs → core.mjs} +0 -0
- /package/dist/{core/index.mjs.map → core.mjs.map} +0 -0
- /package/dist/{react/index.js → react.js} +0 -0
- /package/dist/{react/index.js.map → react.js.map} +0 -0
- /package/dist/{react/index.mjs → react.mjs} +0 -0
- /package/dist/{react/index.mjs.map → react.mjs.map} +0 -0
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/endpoint/index.ts
|
|
21
|
+
var endpoint_exports = {};
|
|
22
|
+
__export(endpoint_exports, {
|
|
23
|
+
MultiEndpointClient: () => MultiEndpointClient
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(endpoint_exports);
|
|
26
|
+
|
|
27
|
+
// src/endpoint/multi-endpoint.ts
|
|
28
|
+
var ABI = [
|
|
29
|
+
{
|
|
30
|
+
name: "getActiveAgentEndpoints",
|
|
31
|
+
type: "function",
|
|
32
|
+
stateMutability: "view",
|
|
33
|
+
inputs: [{ name: "agentId", type: "uint256" }],
|
|
34
|
+
outputs: [{
|
|
35
|
+
type: "tuple[]",
|
|
36
|
+
components: [
|
|
37
|
+
{ name: "endpointId", type: "uint256" },
|
|
38
|
+
{ name: "agentId", type: "uint256" },
|
|
39
|
+
{ name: "name", type: "string" },
|
|
40
|
+
{ name: "endpointType", type: "string" },
|
|
41
|
+
{ name: "protocol", type: "string" },
|
|
42
|
+
{ name: "url", type: "string" },
|
|
43
|
+
{ name: "description", type: "string" },
|
|
44
|
+
{ name: "isActive", type: "bool" },
|
|
45
|
+
{ name: "createdAt", type: "uint256" },
|
|
46
|
+
{ name: "updatedAt", type: "uint256" },
|
|
47
|
+
{ name: "createdBy", type: "address" }
|
|
48
|
+
]
|
|
49
|
+
}]
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
name: "getAgentEndpoints",
|
|
53
|
+
type: "function",
|
|
54
|
+
stateMutability: "view",
|
|
55
|
+
inputs: [{ name: "agentId", type: "uint256" }],
|
|
56
|
+
outputs: [{
|
|
57
|
+
type: "tuple[]",
|
|
58
|
+
components: [
|
|
59
|
+
{ name: "endpointId", type: "uint256" },
|
|
60
|
+
{ name: "agentId", type: "uint256" },
|
|
61
|
+
{ name: "name", type: "string" },
|
|
62
|
+
{ name: "endpointType", type: "string" },
|
|
63
|
+
{ name: "protocol", type: "string" },
|
|
64
|
+
{ name: "url", type: "string" },
|
|
65
|
+
{ name: "description", type: "string" },
|
|
66
|
+
{ name: "isActive", type: "bool" },
|
|
67
|
+
{ name: "createdAt", type: "uint256" },
|
|
68
|
+
{ name: "updatedAt", type: "uint256" },
|
|
69
|
+
{ name: "createdBy", type: "address" }
|
|
70
|
+
]
|
|
71
|
+
}]
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
name: "createEndpoint",
|
|
75
|
+
type: "function",
|
|
76
|
+
stateMutability: "nonpayable",
|
|
77
|
+
inputs: [
|
|
78
|
+
{ name: "agentId", type: "uint256" },
|
|
79
|
+
{ name: "name", type: "string" },
|
|
80
|
+
{ name: "endpointType", type: "string" },
|
|
81
|
+
{ name: "protocol", type: "string" },
|
|
82
|
+
{ name: "url", type: "string" },
|
|
83
|
+
{ name: "description", type: "string" }
|
|
84
|
+
],
|
|
85
|
+
outputs: [{ name: "endpointId", type: "uint256" }]
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
name: "getEndpoint",
|
|
89
|
+
type: "function",
|
|
90
|
+
stateMutability: "view",
|
|
91
|
+
inputs: [{ name: "endpointId", type: "uint256" }],
|
|
92
|
+
outputs: [{
|
|
93
|
+
type: "tuple",
|
|
94
|
+
components: [
|
|
95
|
+
{ name: "endpointId", type: "uint256" },
|
|
96
|
+
{ name: "agentId", type: "uint256" },
|
|
97
|
+
{ name: "name", type: "string" },
|
|
98
|
+
{ name: "endpointType", type: "string" },
|
|
99
|
+
{ name: "protocol", type: "string" },
|
|
100
|
+
{ name: "url", type: "string" },
|
|
101
|
+
{ name: "description", type: "string" },
|
|
102
|
+
{ name: "isActive", type: "bool" },
|
|
103
|
+
{ name: "createdAt", type: "uint256" },
|
|
104
|
+
{ name: "updatedAt", type: "uint256" },
|
|
105
|
+
{ name: "createdBy", type: "address" }
|
|
106
|
+
]
|
|
107
|
+
}]
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
name: "getSupportedProtocols",
|
|
111
|
+
type: "function",
|
|
112
|
+
stateMutability: "view",
|
|
113
|
+
inputs: [],
|
|
114
|
+
outputs: [{ type: "string[]" }]
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
name: "getAgentEndpointStats",
|
|
118
|
+
type: "function",
|
|
119
|
+
stateMutability: "view",
|
|
120
|
+
inputs: [{ name: "agentId", type: "uint256" }],
|
|
121
|
+
outputs: [
|
|
122
|
+
{ name: "totalEndpoints", type: "uint256" },
|
|
123
|
+
{ name: "activeEndpoints", type: "uint256" },
|
|
124
|
+
{ name: "httpEndpoints", type: "uint256" },
|
|
125
|
+
{ name: "websocketEndpoints", type: "uint256" },
|
|
126
|
+
{ name: "grpcEndpoints", type: "uint256" }
|
|
127
|
+
]
|
|
128
|
+
}
|
|
129
|
+
];
|
|
130
|
+
var MultiEndpointClient = class {
|
|
131
|
+
address;
|
|
132
|
+
publicClient;
|
|
133
|
+
constructor(config, publicClient) {
|
|
134
|
+
this.address = config.address;
|
|
135
|
+
this.publicClient = publicClient ?? null;
|
|
136
|
+
}
|
|
137
|
+
setPublicClient(client) {
|
|
138
|
+
this.publicClient = client;
|
|
139
|
+
}
|
|
140
|
+
async getActiveEndpoints(agentId) {
|
|
141
|
+
if (!this.publicClient) throw new Error("publicClient not set");
|
|
142
|
+
return await this.publicClient.readContract({
|
|
143
|
+
address: this.address,
|
|
144
|
+
abi: ABI,
|
|
145
|
+
functionName: "getActiveAgentEndpoints",
|
|
146
|
+
args: [agentId]
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
async getAllEndpoints(agentId) {
|
|
150
|
+
if (!this.publicClient) throw new Error("publicClient not set");
|
|
151
|
+
return await this.publicClient.readContract({
|
|
152
|
+
address: this.address,
|
|
153
|
+
abi: ABI,
|
|
154
|
+
functionName: "getAgentEndpoints",
|
|
155
|
+
args: [agentId]
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
async getEndpoint(endpointId) {
|
|
159
|
+
if (!this.publicClient) throw new Error("publicClient not set");
|
|
160
|
+
return await this.publicClient.readContract({
|
|
161
|
+
address: this.address,
|
|
162
|
+
abi: ABI,
|
|
163
|
+
functionName: "getEndpoint",
|
|
164
|
+
args: [endpointId]
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
async getStats(agentId) {
|
|
168
|
+
if (!this.publicClient) throw new Error("publicClient not set");
|
|
169
|
+
return await this.publicClient.readContract({
|
|
170
|
+
address: this.address,
|
|
171
|
+
abi: ABI,
|
|
172
|
+
functionName: "getAgentEndpointStats",
|
|
173
|
+
args: [agentId]
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
/** Pick best active endpoint for the agent — prefer HTTP, take first active */
|
|
177
|
+
async pickBestEndpoint(agentId) {
|
|
178
|
+
const endpoints = await this.getActiveEndpoints(agentId);
|
|
179
|
+
if (endpoints.length === 0) return null;
|
|
180
|
+
const http = endpoints.find((e) => e.protocol === "HTTP");
|
|
181
|
+
return http ?? endpoints[0] ?? null;
|
|
182
|
+
}
|
|
183
|
+
/** Pick any active endpoint URL — for MCP connector */
|
|
184
|
+
async getBestMCPUrl(agentId) {
|
|
185
|
+
const best = await this.pickBestEndpoint(agentId);
|
|
186
|
+
return best?.url ?? null;
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
190
|
+
0 && (module.exports = {
|
|
191
|
+
MultiEndpointClient
|
|
192
|
+
});
|
|
193
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/endpoint/index.ts","../../src/endpoint/multi-endpoint.ts"],"sourcesContent":["export * from './multi-endpoint'\n","/**\n * MultiEndpointRegistry SDK\n * OxaChain L1 + Sepolia — multi-endpoint management for AI Agents\n */\nimport { type PublicClient, type WalletClient, type Address, type Hash, type Chain } from 'viem'\n\nexport interface EndpointRecord {\n endpointId: bigint\n agentId: bigint\n name: string\n endpointType: string\n protocol: string\n url: string\n description: string\n isActive: boolean\n createdAt: bigint\n updatedAt: bigint\n createdBy: Address\n}\n\nexport interface MultiEndpointConfig {\n address: Address\n}\n\nconst ABI = [\n {\n name: 'getActiveAgentEndpoints',\n type: 'function',\n stateMutability: 'view',\n inputs: [{ name: 'agentId', type: 'uint256' }],\n outputs: [{\n type: 'tuple[]',\n components: [\n { name: 'endpointId', type: 'uint256' },\n { name: 'agentId', type: 'uint256' },\n { name: 'name', type: 'string' },\n { name: 'endpointType', type: 'string' },\n { name: 'protocol', type: 'string' },\n { name: 'url', type: 'string' },\n { name: 'description', type: 'string' },\n { name: 'isActive', type: 'bool' },\n { name: 'createdAt', type: 'uint256' },\n { name: 'updatedAt', type: 'uint256' },\n { name: 'createdBy', type: 'address' },\n ]\n }],\n },\n {\n name: 'getAgentEndpoints',\n type: 'function',\n stateMutability: 'view',\n inputs: [{ name: 'agentId', type: 'uint256' }],\n outputs: [{\n type: 'tuple[]',\n components: [\n { name: 'endpointId', type: 'uint256' },\n { name: 'agentId', type: 'uint256' },\n { name: 'name', type: 'string' },\n { name: 'endpointType', type: 'string' },\n { name: 'protocol', type: 'string' },\n { name: 'url', type: 'string' },\n { name: 'description', type: 'string' },\n { name: 'isActive', type: 'bool' },\n { name: 'createdAt', type: 'uint256' },\n { name: 'updatedAt', type: 'uint256' },\n { name: 'createdBy', type: 'address' },\n ]\n }],\n },\n {\n name: 'createEndpoint',\n type: 'function',\n stateMutability: 'nonpayable',\n inputs: [\n { name: 'agentId', type: 'uint256' },\n { name: 'name', type: 'string' },\n { name: 'endpointType', type: 'string' },\n { name: 'protocol', type: 'string' },\n { name: 'url', type: 'string' },\n { name: 'description', type: 'string' },\n ],\n outputs: [{ name: 'endpointId', type: 'uint256' }],\n },\n {\n name: 'getEndpoint',\n type: 'function',\n stateMutability: 'view',\n inputs: [{ name: 'endpointId', type: 'uint256' }],\n outputs: [{\n type: 'tuple',\n components: [\n { name: 'endpointId', type: 'uint256' },\n { name: 'agentId', type: 'uint256' },\n { name: 'name', type: 'string' },\n { name: 'endpointType', type: 'string' },\n { name: 'protocol', type: 'string' },\n { name: 'url', type: 'string' },\n { name: 'description', type: 'string' },\n { name: 'isActive', type: 'bool' },\n { name: 'createdAt', type: 'uint256' },\n { name: 'updatedAt', type: 'uint256' },\n { name: 'createdBy', type: 'address' },\n ]\n }],\n },\n {\n name: 'getSupportedProtocols',\n type: 'function',\n stateMutability: 'view',\n inputs: [],\n outputs: [{ type: 'string[]' }],\n },\n {\n name: 'getAgentEndpointStats',\n type: 'function',\n stateMutability: 'view',\n inputs: [{ name: 'agentId', type: 'uint256' }],\n outputs: [\n { name: 'totalEndpoints', type: 'uint256' },\n { name: 'activeEndpoints', type: 'uint256' },\n { name: 'httpEndpoints', type: 'uint256' },\n { name: 'websocketEndpoints', type: 'uint256' },\n { name: 'grpcEndpoints', type: 'uint256' },\n ],\n },\n] as const\n\nexport class MultiEndpointClient {\n private address: Address\n private publicClient: PublicClient | null\n\n constructor(config: MultiEndpointConfig, publicClient?: PublicClient) {\n this.address = config.address\n this.publicClient = publicClient ?? null\n }\n\n setPublicClient(client: PublicClient) {\n this.publicClient = client\n }\n\n async getActiveEndpoints(agentId: bigint): Promise<EndpointRecord[]> {\n if (!this.publicClient) throw new Error('publicClient not set')\n return (await this.publicClient.readContract({\n address: this.address,\n abi: ABI,\n functionName: 'getActiveAgentEndpoints',\n args: [agentId],\n })) as EndpointRecord[]\n }\n\n async getAllEndpoints(agentId: bigint): Promise<EndpointRecord[]> {\n if (!this.publicClient) throw new Error('publicClient not set')\n return (await this.publicClient.readContract({\n address: this.address,\n abi: ABI,\n functionName: 'getAgentEndpoints',\n args: [agentId],\n })) as EndpointRecord[]\n }\n\n async getEndpoint(endpointId: bigint): Promise<EndpointRecord> {\n if (!this.publicClient) throw new Error('publicClient not set')\n return (await this.publicClient.readContract({\n address: this.address,\n abi: ABI,\n functionName: 'getEndpoint',\n args: [endpointId],\n })) as EndpointRecord\n }\n\n async getStats(agentId: bigint) {\n if (!this.publicClient) throw new Error('publicClient not set')\n return (await this.publicClient.readContract({\n address: this.address,\n abi: ABI,\n functionName: 'getAgentEndpointStats',\n args: [agentId],\n })) as [bigint, bigint, bigint, bigint, bigint]\n }\n\n /** Pick best active endpoint for the agent — prefer HTTP, take first active */\n async pickBestEndpoint(agentId: bigint): Promise<EndpointRecord | null> {\n const endpoints = await this.getActiveEndpoints(agentId)\n if (endpoints.length === 0) return null\n // prefer HTTP endpoints\n const http = endpoints.find(e => e.protocol === 'HTTP')\n return http ?? endpoints[0] ?? null\n }\n\n /** Pick any active endpoint URL — for MCP connector */\n async getBestMCPUrl(agentId: bigint): Promise<string | null> {\n const best = await this.pickBestEndpoint(agentId)\n return best?.url ?? null\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACwBA,IAAM,MAAM;AAAA,EACV;AAAA,IACE,MAAM;AAAA,IACN,MAAM;AAAA,IACN,iBAAiB;AAAA,IACjB,QAAQ,CAAC,EAAE,MAAM,WAAW,MAAM,UAAU,CAAC;AAAA,IAC7C,SAAS,CAAC;AAAA,MACR,MAAM;AAAA,MACN,YAAY;AAAA,QACV,EAAE,MAAM,cAAc,MAAM,UAAU;AAAA,QACtC,EAAE,MAAM,WAAW,MAAM,UA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nB,CAAC;AAAA,EACH;AAAA,EAEA,MAAM,SAAS,SAAiB;AAC9B,QAAI,CAAC,KAAK,aAAc,OAAM,IAAI,MAAM,sBAAsB;AAC9D,WAAQ,MAAM,KAAK,aAAa,aAAa;AAAA,MAC3C,SAAS,KAAK;AAAA,MACd,KAAK;AAAA,MACL,cAAc;AAAA,MACd,MAAM,CAAC,OAAO;AAAA,IAChB,CAAC;AAAA,EACH;AAAA;AAAA,EAGA,MAAM,iBAAiB,SAAiD;AACtE,UAAM,YAAY,MAAM,KAAK,mBAAmB,OAAO;AACvD,QAAI,UAAU,WAAW,EAAG,QAAO;AAEnC,UAAM,OAAO,UAAU,KAAK,OAAK,EAAE,aAAa,MAAM;AACtD,WAAO,QAAQ,UAAU,CAAC,KAAK;AAAA,EACjC;AAAA;AAAA,EAGA,MAAM,cAAc,SAAyC;AAC3D,UAAM,OAAO,MAAM,KAAK,iBAAiB,OAAO;AAChD,WAAO,MAAM,OAAO;AAAA,EACtB;AACF;","names":[]}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
// src/endpoint/multi-endpoint.ts
|
|
2
|
+
var ABI = [
|
|
3
|
+
{
|
|
4
|
+
name: "getActiveAgentEndpoints",
|
|
5
|
+
type: "function",
|
|
6
|
+
stateMutability: "view",
|
|
7
|
+
inputs: [{ name: "agentId", type: "uint256" }],
|
|
8
|
+
outputs: [{
|
|
9
|
+
type: "tuple[]",
|
|
10
|
+
components: [
|
|
11
|
+
{ name: "endpointId", type: "uint256" },
|
|
12
|
+
{ name: "agentId", type: "uint256" },
|
|
13
|
+
{ name: "name", type: "string" },
|
|
14
|
+
{ name: "endpointType", type: "string" },
|
|
15
|
+
{ name: "protocol", type: "string" },
|
|
16
|
+
{ name: "url", type: "string" },
|
|
17
|
+
{ name: "description", type: "string" },
|
|
18
|
+
{ name: "isActive", type: "bool" },
|
|
19
|
+
{ name: "createdAt", type: "uint256" },
|
|
20
|
+
{ name: "updatedAt", type: "uint256" },
|
|
21
|
+
{ name: "createdBy", type: "address" }
|
|
22
|
+
]
|
|
23
|
+
}]
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
name: "getAgentEndpoints",
|
|
27
|
+
type: "function",
|
|
28
|
+
stateMutability: "view",
|
|
29
|
+
inputs: [{ name: "agentId", type: "uint256" }],
|
|
30
|
+
outputs: [{
|
|
31
|
+
type: "tuple[]",
|
|
32
|
+
components: [
|
|
33
|
+
{ name: "endpointId", type: "uint256" },
|
|
34
|
+
{ name: "agentId", type: "uint256" },
|
|
35
|
+
{ name: "name", type: "string" },
|
|
36
|
+
{ name: "endpointType", type: "string" },
|
|
37
|
+
{ name: "protocol", type: "string" },
|
|
38
|
+
{ name: "url", type: "string" },
|
|
39
|
+
{ name: "description", type: "string" },
|
|
40
|
+
{ name: "isActive", type: "bool" },
|
|
41
|
+
{ name: "createdAt", type: "uint256" },
|
|
42
|
+
{ name: "updatedAt", type: "uint256" },
|
|
43
|
+
{ name: "createdBy", type: "address" }
|
|
44
|
+
]
|
|
45
|
+
}]
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
name: "createEndpoint",
|
|
49
|
+
type: "function",
|
|
50
|
+
stateMutability: "nonpayable",
|
|
51
|
+
inputs: [
|
|
52
|
+
{ name: "agentId", type: "uint256" },
|
|
53
|
+
{ name: "name", type: "string" },
|
|
54
|
+
{ name: "endpointType", type: "string" },
|
|
55
|
+
{ name: "protocol", type: "string" },
|
|
56
|
+
{ name: "url", type: "string" },
|
|
57
|
+
{ name: "description", type: "string" }
|
|
58
|
+
],
|
|
59
|
+
outputs: [{ name: "endpointId", type: "uint256" }]
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
name: "getEndpoint",
|
|
63
|
+
type: "function",
|
|
64
|
+
stateMutability: "view",
|
|
65
|
+
inputs: [{ name: "endpointId", type: "uint256" }],
|
|
66
|
+
outputs: [{
|
|
67
|
+
type: "tuple",
|
|
68
|
+
components: [
|
|
69
|
+
{ name: "endpointId", type: "uint256" },
|
|
70
|
+
{ name: "agentId", type: "uint256" },
|
|
71
|
+
{ name: "name", type: "string" },
|
|
72
|
+
{ name: "endpointType", type: "string" },
|
|
73
|
+
{ name: "protocol", type: "string" },
|
|
74
|
+
{ name: "url", type: "string" },
|
|
75
|
+
{ name: "description", type: "string" },
|
|
76
|
+
{ name: "isActive", type: "bool" },
|
|
77
|
+
{ name: "createdAt", type: "uint256" },
|
|
78
|
+
{ name: "updatedAt", type: "uint256" },
|
|
79
|
+
{ name: "createdBy", type: "address" }
|
|
80
|
+
]
|
|
81
|
+
}]
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
name: "getSupportedProtocols",
|
|
85
|
+
type: "function",
|
|
86
|
+
stateMutability: "view",
|
|
87
|
+
inputs: [],
|
|
88
|
+
outputs: [{ type: "string[]" }]
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
name: "getAgentEndpointStats",
|
|
92
|
+
type: "function",
|
|
93
|
+
stateMutability: "view",
|
|
94
|
+
inputs: [{ name: "agentId", type: "uint256" }],
|
|
95
|
+
outputs: [
|
|
96
|
+
{ name: "totalEndpoints", type: "uint256" },
|
|
97
|
+
{ name: "activeEndpoints", type: "uint256" },
|
|
98
|
+
{ name: "httpEndpoints", type: "uint256" },
|
|
99
|
+
{ name: "websocketEndpoints", type: "uint256" },
|
|
100
|
+
{ name: "grpcEndpoints", type: "uint256" }
|
|
101
|
+
]
|
|
102
|
+
}
|
|
103
|
+
];
|
|
104
|
+
var MultiEndpointClient = class {
|
|
105
|
+
address;
|
|
106
|
+
publicClient;
|
|
107
|
+
constructor(config, publicClient) {
|
|
108
|
+
this.address = config.address;
|
|
109
|
+
this.publicClient = publicClient ?? null;
|
|
110
|
+
}
|
|
111
|
+
setPublicClient(client) {
|
|
112
|
+
this.publicClient = client;
|
|
113
|
+
}
|
|
114
|
+
async getActiveEndpoints(agentId) {
|
|
115
|
+
if (!this.publicClient) throw new Error("publicClient not set");
|
|
116
|
+
return await this.publicClient.readContract({
|
|
117
|
+
address: this.address,
|
|
118
|
+
abi: ABI,
|
|
119
|
+
functionName: "getActiveAgentEndpoints",
|
|
120
|
+
args: [agentId]
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
async getAllEndpoints(agentId) {
|
|
124
|
+
if (!this.publicClient) throw new Error("publicClient not set");
|
|
125
|
+
return await this.publicClient.readContract({
|
|
126
|
+
address: this.address,
|
|
127
|
+
abi: ABI,
|
|
128
|
+
functionName: "getAgentEndpoints",
|
|
129
|
+
args: [agentId]
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
async getEndpoint(endpointId) {
|
|
133
|
+
if (!this.publicClient) throw new Error("publicClient not set");
|
|
134
|
+
return await this.publicClient.readContract({
|
|
135
|
+
address: this.address,
|
|
136
|
+
abi: ABI,
|
|
137
|
+
functionName: "getEndpoint",
|
|
138
|
+
args: [endpointId]
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
async getStats(agentId) {
|
|
142
|
+
if (!this.publicClient) throw new Error("publicClient not set");
|
|
143
|
+
return await this.publicClient.readContract({
|
|
144
|
+
address: this.address,
|
|
145
|
+
abi: ABI,
|
|
146
|
+
functionName: "getAgentEndpointStats",
|
|
147
|
+
args: [agentId]
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
/** Pick best active endpoint for the agent — prefer HTTP, take first active */
|
|
151
|
+
async pickBestEndpoint(agentId) {
|
|
152
|
+
const endpoints = await this.getActiveEndpoints(agentId);
|
|
153
|
+
if (endpoints.length === 0) return null;
|
|
154
|
+
const http = endpoints.find((e) => e.protocol === "HTTP");
|
|
155
|
+
return http ?? endpoints[0] ?? null;
|
|
156
|
+
}
|
|
157
|
+
/** Pick any active endpoint URL — for MCP connector */
|
|
158
|
+
async getBestMCPUrl(agentId) {
|
|
159
|
+
const best = await this.pickBestEndpoint(agentId);
|
|
160
|
+
return best?.url ?? null;
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
export {
|
|
164
|
+
MultiEndpointClient
|
|
165
|
+
};
|
|
166
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/endpoint/multi-endpoint.ts"],"sourcesContent":["/**\n * MultiEndpointRegistry SDK\n * OxaChain L1 + Sepolia — multi-endpoint management for AI Agents\n */\nimport { type PublicClient, type WalletClient, type Address, type Hash, type Chain } from 'viem'\n\nexport interface EndpointRecord {\n endpointId: bigint\n agentId: bigint\n name: string\n endpointType: string\n protocol: string\n url: string\n description: string\n isActive: boolean\n createdAt: bigint\n updatedAt: bigint\n createdBy: Address\n}\n\nexport interface MultiEndpointConfig {\n address: Address\n}\n\nconst ABI = [\n {\n name: 'getActiveAgentEndpoints',\n type: 'function',\n stateMutability: 'view',\n inputs: [{ name: 'agentId', type: 'uint256' }],\n outputs: [{\n type: 'tuple[]',\n components: [\n { name: 'endpointId', type: 'uint256' },\n { name: 'agentId', type: 'uint256' },\n { name: 'name', type: 'string' },\n { name: 'endpointType', type: 'string' },\n { name: 'protocol', type: 'string' },\n { name: 'url', type: 'string' },\n { name: 'description', type: 'string' },\n { name: 'isActive', type: 'bool' },\n { name: 'createdAt', type: 'uint256' },\n { name: 'updatedAt', type: 'uint256' },\n { name: 'createdBy', type: 'address' },\n ]\n }],\n },\n {\n name: 'getAgentEndpoints',\n type: 'function',\n stateMutability: 'view',\n inputs: [{ name: 'agentId', type: 'uint256' }],\n outputs: [{\n type: 'tuple[]',\n components: [\n { name: 'endpointId', type: 'uint256' },\n { name: 'agentId', type: 'uint256' },\n { name: 'name', type: 'string' },\n { name: 'endpointType', type: 'string' },\n { name: 'protocol', type: 'string' },\n { name: 'url', type: 'string' },\n { name: 'description', type: 'string' },\n { name: 'isActive', type: 'bool' },\n { name: 'createdAt', type: 'uint256' },\n { name: 'updatedAt', type: 'uint256' },\n { name: 'createdBy', type: 'address' },\n ]\n }],\n },\n {\n name: 'createEndpoint',\n type: 'function',\n stateMutability: 'nonpayable',\n inputs: [\n { name: 'agentId', type: 'uint256' },\n { name: 'name', type: 'string' },\n { name: 'endpointType', type: 'string' },\n { name: 'protocol', type: 'string' },\n { name: 'url', type: 'string' },\n { name: 'description', type: 'string' },\n ],\n outputs: [{ name: 'endpointId', type: 'uint256' }],\n },\n {\n name: 'getEndpoint',\n type: 'function',\n stateMutability: 'view',\n inputs: [{ name: 'endpointId', type: 'uint256' }],\n outputs: [{\n type: 'tuple',\n components: [\n { name: 'endpointId', type: 'uint256' },\n { name: 'agentId', type: 'uint256' },\n { name: 'name', type: 'string' },\n { name: 'endpointType', type: 'string' },\n { name: 'protocol', type: 'string' },\n { name: 'url', type: 'string' },\n { name: 'description', type: 'string' },\n { name: 'isActive', type: 'bool' },\n { name: 'createdAt', type: 'uint256' },\n { name: 'updatedAt', type: 'uint256' },\n { name: 'createdBy', type: 'address' },\n ]\n }],\n },\n {\n name: 'getSupportedProtocols',\n type: 'function',\n stateMutability: 'view',\n inputs: [],\n outputs: [{ type: 'string[]' }],\n },\n {\n name: 'getAgentEndpointStats',\n type: 'function',\n stateMutability: 'view',\n inputs: [{ name: 'agentId', type: 'uint256' }],\n outputs: [\n { name: 'totalEndpoints', type: 'uint256' },\n { name: 'activeEndpoints', type: 'uint256' },\n { name: 'httpEndpoints', type: 'uint256' },\n { name: 'websocketEndpoints', type: 'uint256' },\n { name: 'grpcEndpoints', type: 'uint256' },\n ],\n },\n] as const\n\nexport class MultiEndpointClient {\n private address: Address\n private publicClient: PublicClient | null\n\n constructor(config: MultiEndpointConfig, publicClient?: PublicClient) {\n this.address = config.address\n this.publicClient = publicClient ?? null\n }\n\n setPublicClient(client: PublicClient) {\n this.publicClient = client\n }\n\n async getActiveEndpoints(agentId: bigint): Promise<EndpointRecord[]> {\n if (!this.publicClient) throw new Error('publicClient not set')\n return (await this.publicClient.readContract({\n address: this.address,\n abi: ABI,\n functionName: 'getActiveAgentEndpoints',\n args: [agentId],\n })) as EndpointRecord[]\n }\n\n async getAllEndpoints(agentId: bigint): Promise<EndpointRecord[]> {\n if (!this.publicClient) throw new Error('publicClient not set')\n return (await this.publicClient.readContract({\n address: this.address,\n abi: ABI,\n functionName: 'getAgentEndpoints',\n args: [agentId],\n })) as EndpointRecord[]\n }\n\n async getEndpoint(endpointId: bigint): Promise<EndpointRecord> {\n if (!this.publicClient) throw new Error('publicClient not set')\n return (await this.publicClient.readContract({\n address: this.address,\n abi: ABI,\n functionName: 'getEndpoint',\n args: [endpointId],\n })) as EndpointRecord\n }\n\n async getStats(agentId: bigint) {\n if (!this.publicClient) throw new Error('publicClient not set')\n return (await this.publicClient.readContract({\n address: this.address,\n abi: ABI,\n functionName: 'getAgentEndpointStats',\n args: [agentId],\n })) as [bigint, bigint, bigint, bigint, bigint]\n }\n\n /** Pick best active endpoint for the agent — prefer HTTP, take first active */\n async pickBestEndpoint(agentId: bigint): Promise<EndpointRecord | null> {\n const endpoints = await this.getActiveEndpoints(agentId)\n if (endpoints.length === 0) return null\n // prefer HTTP endpoints\n const http = endpoints.find(e => e.protocol === 'HTTP')\n return http ?? endpoints[0] ?? null\n }\n\n /** Pick any active endpoint URL — for MCP connector */\n async getBestMCPUrl(agentId: bigint): Promise<string | null> {\n const best = await this.pickBestEndpoint(agentId)\n return best?.url ?? null\n }\n}\n"],"mappings":";AAwBA,IAAM,MAAM;AAAA,EACV;AAAA,IACE,MAAM;AAAA,IACN,MAAM;AAAA,IACN,iBAAiB;AAAA,IACjB,QAAQ,CAAC,EAAE,MAAM,WAAW,MAAM,UAAU,CAAC;AAAA,IAC7C,SAAS,CAAC;AAAA,MACR,MAAM;AAAA,MACN,YAAY;AAAA,QACV,EAAE,MAAM,cAAc,MAAM,UAAU;AAAA,QACtC,EAAE,MAAM,WAAW,MAAM,UAAU;AAAA,QACnC,EAAE,MAAM,QAAQ,MAAM,SAAS;AAAA,QAC/B,EAAE,MAAM,gBAAgB,MAAM,SAAS;AAAA,QACvC,EAAE,MAAM,YAAY,MAAM,SAAS;AAAA,QACnC,EAAE,MAAM,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C,SAAS,KAAK;AAAA,MACd,KAAK;AAAA,MACL,cAAc;AAAA,MACd,MAAM,CAAC,OAAO;AAAA,IAChB,CAAC;AAAA,EACH;AAAA;AAAA,EAGA,MAAM,iBAAiB,SAAiD;AACtE,UAAM,YAAY,MAAM,KAAK,mBAAmB,OAAO;AACvD,QAAI,UAAU,WAAW,EAAG,QAAO;AAEnC,UAAM,OAAO,UAAU,KAAK,OAAK,EAAE,aAAa,MAAM;AACtD,WAAO,QAAQ,UAAU,CAAC,KAAK;AAAA,EACjC;AAAA;AAAA,EAGA,MAAM,cAAc,SAAyC;AAC3D,UAAM,OAAO,MAAM,KAAK,iBAAiB,OAAO;AAChD,WAAO,MAAM,OAAO;AAAA,EACtB;AACF;","names":[]}
|
|
@@ -0,0 +1,209 @@
|
|
|
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
|
+
multiEndpointRegistry: Address;
|
|
174
|
+
};
|
|
175
|
+
ipfsGateways: string[];
|
|
176
|
+
rpcUrl?: string;
|
|
177
|
+
}
|
|
178
|
+
declare const KNOWN_CHAINS: Record<number, ChainConfig>;
|
|
179
|
+
interface ConfigRegistryOpts {
|
|
180
|
+
contractAddress: Address;
|
|
181
|
+
publicClient: PublicClient;
|
|
182
|
+
walletClient: WalletClient;
|
|
183
|
+
}
|
|
184
|
+
declare class ConfigurationRegistry {
|
|
185
|
+
private address;
|
|
186
|
+
private publicClient;
|
|
187
|
+
private walletClient;
|
|
188
|
+
constructor(opts: ConfigRegistryOpts);
|
|
189
|
+
private get account();
|
|
190
|
+
set(key: string, value: string): Promise<Hash>;
|
|
191
|
+
get(key: string): Promise<string>;
|
|
192
|
+
getAll(): Promise<Record<string, string>>;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
interface UseAgentRunnerConfig {
|
|
196
|
+
agentId: number;
|
|
197
|
+
chainConfig?: ChainConfig;
|
|
198
|
+
ipfsGateways?: string[];
|
|
199
|
+
}
|
|
200
|
+
interface UseAgentRunnerResult {
|
|
201
|
+
ctx: AgentRunContext | null;
|
|
202
|
+
isLoading: boolean;
|
|
203
|
+
error: Error | null;
|
|
204
|
+
/** Re-trigger the load (e.g. after connecting wallet or subscribing) */
|
|
205
|
+
refetch: () => void;
|
|
206
|
+
}
|
|
207
|
+
declare function useAgentRunner(config: UseAgentRunnerConfig): UseAgentRunnerResult;
|
|
208
|
+
|
|
209
|
+
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 };
|