tenzro-sdk 0.1.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/LICENSE +201 -0
- package/README.md +107 -0
- package/dist/agent-payments.d.ts +47 -0
- package/dist/agent-payments.d.ts.map +1 -0
- package/dist/agent-payments.js +76 -0
- package/dist/agent-payments.js.map +1 -0
- package/dist/agent.d.ts +177 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +300 -0
- package/dist/agent.js.map +1 -0
- package/dist/ap2.d.ts +54 -0
- package/dist/ap2.d.ts.map +1 -0
- package/dist/ap2.js +88 -0
- package/dist/ap2.js.map +1 -0
- package/dist/app.d.ts +186 -0
- package/dist/app.d.ts.map +1 -0
- package/dist/app.js +317 -0
- package/dist/app.js.map +1 -0
- package/dist/bridge.d.ts +64 -0
- package/dist/bridge.d.ts.map +1 -0
- package/dist/bridge.js +93 -0
- package/dist/bridge.js.map +1 -0
- package/dist/canton.d.ts +36 -0
- package/dist/canton.d.ts.map +1 -0
- package/dist/canton.js +46 -0
- package/dist/canton.js.map +1 -0
- package/dist/circuit-breaker.d.ts +35 -0
- package/dist/circuit-breaker.d.ts.map +1 -0
- package/dist/circuit-breaker.js +53 -0
- package/dist/circuit-breaker.js.map +1 -0
- package/dist/client.d.ts +134 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +265 -0
- package/dist/client.js.map +1 -0
- package/dist/compliance.d.ts +83 -0
- package/dist/compliance.d.ts.map +1 -0
- package/dist/compliance.js +74 -0
- package/dist/compliance.js.map +1 -0
- package/dist/config.d.ts +10 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +24 -0
- package/dist/config.js.map +1 -0
- package/dist/contract.d.ts +68 -0
- package/dist/contract.d.ts.map +1 -0
- package/dist/contract.js +59 -0
- package/dist/contract.js.map +1 -0
- package/dist/crypto.d.ts +112 -0
- package/dist/crypto.d.ts.map +1 -0
- package/dist/crypto.js +97 -0
- package/dist/crypto.js.map +1 -0
- package/dist/custody.d.ts +114 -0
- package/dist/custody.d.ts.map +1 -0
- package/dist/custody.js +96 -0
- package/dist/custody.js.map +1 -0
- package/dist/debridge.d.ts +129 -0
- package/dist/debridge.d.ts.map +1 -0
- package/dist/debridge.js +93 -0
- package/dist/debridge.js.map +1 -0
- package/dist/erc7802.d.ts +36 -0
- package/dist/erc7802.d.ts.map +1 -0
- package/dist/erc7802.js +52 -0
- package/dist/erc7802.js.map +1 -0
- package/dist/events.d.ts +112 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +70 -0
- package/dist/events.js.map +1 -0
- package/dist/governance.d.ts +55 -0
- package/dist/governance.d.ts.map +1 -0
- package/dist/governance.js +77 -0
- package/dist/governance.js.map +1 -0
- package/dist/identity.d.ts +102 -0
- package/dist/identity.d.ts.map +1 -0
- package/dist/identity.js +147 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +67 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +85 -0
- package/dist/index.js.map +1 -0
- package/dist/inference.d.ts +27 -0
- package/dist/inference.d.ts.map +1 -0
- package/dist/inference.js +43 -0
- package/dist/inference.js.map +1 -0
- package/dist/marketplace.d.ts +44 -0
- package/dist/marketplace.d.ts.map +1 -0
- package/dist/marketplace.js +74 -0
- package/dist/marketplace.js.map +1 -0
- package/dist/nanopayment.d.ts +53 -0
- package/dist/nanopayment.d.ts.map +1 -0
- package/dist/nanopayment.js +81 -0
- package/dist/nanopayment.js.map +1 -0
- package/dist/nft.d.ts +127 -0
- package/dist/nft.d.ts.map +1 -0
- package/dist/nft.js +99 -0
- package/dist/nft.js.map +1 -0
- package/dist/payment.d.ts +71 -0
- package/dist/payment.d.ts.map +1 -0
- package/dist/payment.js +105 -0
- package/dist/payment.js.map +1 -0
- package/dist/provider.d.ts +351 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +368 -0
- package/dist/provider.js.map +1 -0
- package/dist/rpc.d.ts +35 -0
- package/dist/rpc.d.ts.map +1 -0
- package/dist/rpc.js +127 -0
- package/dist/rpc.js.map +1 -0
- package/dist/settlement.d.ts +52 -0
- package/dist/settlement.d.ts.map +1 -0
- package/dist/settlement.js +86 -0
- package/dist/settlement.js.map +1 -0
- package/dist/skill.d.ts +55 -0
- package/dist/skill.d.ts.map +1 -0
- package/dist/skill.js +79 -0
- package/dist/skill.js.map +1 -0
- package/dist/staking.d.ts +42 -0
- package/dist/staking.d.ts.map +1 -0
- package/dist/staking.js +62 -0
- package/dist/staking.js.map +1 -0
- package/dist/streaming.d.ts +83 -0
- package/dist/streaming.d.ts.map +1 -0
- package/dist/streaming.js +193 -0
- package/dist/streaming.js.map +1 -0
- package/dist/task.d.ts +46 -0
- package/dist/task.d.ts.map +1 -0
- package/dist/task.js +76 -0
- package/dist/task.js.map +1 -0
- package/dist/tee.d.ts +88 -0
- package/dist/tee.d.ts.map +1 -0
- package/dist/tee.js +62 -0
- package/dist/tee.js.map +1 -0
- package/dist/token.d.ts +165 -0
- package/dist/token.d.ts.map +1 -0
- package/dist/token.js +80 -0
- package/dist/token.js.map +1 -0
- package/dist/tool.d.ts +55 -0
- package/dist/tool.d.ts.map +1 -0
- package/dist/tool.js +79 -0
- package/dist/tool.js.map +1 -0
- package/dist/types.d.ts +1318 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +117 -0
- package/dist/types.js.map +1 -0
- package/dist/wallet.d.ts +44 -0
- package/dist/wallet.d.ts.map +1 -0
- package/dist/wallet.js +75 -0
- package/dist/wallet.js.map +1 -0
- package/dist/zk.d.ts +66 -0
- package/dist/zk.d.ts.map +1 -0
- package/dist/zk.js +58 -0
- package/dist/zk.js.map +1 -0
- package/package.json +41 -0
package/dist/agent.js
ADDED
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AgentClient = void 0;
|
|
4
|
+
// Simple UUID v4 generator for browser/node compatibility
|
|
5
|
+
function generateUUID() {
|
|
6
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
|
|
7
|
+
const r = Math.random() * 16 | 0;
|
|
8
|
+
const v = c === 'x' ? r : (r & 0x3 | 0x8);
|
|
9
|
+
return v.toString(16);
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Client for AI agent operations.
|
|
14
|
+
* Supports agent registration, messaging, and task delegation.
|
|
15
|
+
*/
|
|
16
|
+
class AgentClient {
|
|
17
|
+
rpc;
|
|
18
|
+
constructor(rpc) {
|
|
19
|
+
this.rpc = rpc;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Register a new AI agent on the network.
|
|
23
|
+
* @param agentId - Unique identifier for the agent
|
|
24
|
+
* @param name - Human-readable name
|
|
25
|
+
* @param capabilities - List of agent capabilities
|
|
26
|
+
* @returns Registration response with agent ID and status
|
|
27
|
+
*/
|
|
28
|
+
async register(agentId, name, capabilities) {
|
|
29
|
+
return this.rpc.call("tenzro_registerAgent", [
|
|
30
|
+
{
|
|
31
|
+
agent_id: agentId,
|
|
32
|
+
name,
|
|
33
|
+
capabilities,
|
|
34
|
+
},
|
|
35
|
+
]);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Send a message to another agent.
|
|
39
|
+
* @param agentId - Target agent identifier
|
|
40
|
+
* @param message - Message content
|
|
41
|
+
* @returns Message response with payload and message ID
|
|
42
|
+
*/
|
|
43
|
+
async sendMessage(agentId, message) {
|
|
44
|
+
return this.rpc.call("tenzro_sendAgentMessage", [
|
|
45
|
+
{
|
|
46
|
+
agent_id: agentId,
|
|
47
|
+
message,
|
|
48
|
+
},
|
|
49
|
+
]);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Delegate a task to an agent using the A2A protocol.
|
|
53
|
+
* @param agentId - Target agent identifier
|
|
54
|
+
* @param taskDescription - Description of the task to delegate
|
|
55
|
+
* @returns Task delegation response with ID and status
|
|
56
|
+
*/
|
|
57
|
+
async delegateTask(agentId, taskDescription) {
|
|
58
|
+
return this.rpc.post("/a2a", {
|
|
59
|
+
jsonrpc: "2.0",
|
|
60
|
+
method: "tasks/send",
|
|
61
|
+
params: {
|
|
62
|
+
id: generateUUID(),
|
|
63
|
+
message: {
|
|
64
|
+
role: "user",
|
|
65
|
+
parts: [{ type: "text", text: taskDescription }],
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
id: 1,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* List all registered agents on the network.
|
|
73
|
+
* @returns Array of agent identities
|
|
74
|
+
*/
|
|
75
|
+
async listAgents() {
|
|
76
|
+
return this.rpc.call("tenzro_listAgents");
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Spawn a child agent under a parent agent.
|
|
80
|
+
* @param parentId - The parent agent's ID
|
|
81
|
+
* @param name - Name for the new child agent
|
|
82
|
+
* @param capabilities - List of capability strings for the child agent
|
|
83
|
+
* @returns Spawned agent info with agent_id, parent_id, and name
|
|
84
|
+
*/
|
|
85
|
+
async spawnAgent(parentId, name, capabilities) {
|
|
86
|
+
return this.rpc.call("tenzro_spawnAgent", [
|
|
87
|
+
{ parent_id: parentId, name, capabilities },
|
|
88
|
+
]);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Run an agentic task loop for an agent.
|
|
92
|
+
* The agent calls an LLM with built-in tools (spawn_agent, delegate_task,
|
|
93
|
+
* collect_results, complete) and executes them iteratively until done.
|
|
94
|
+
* @param agentId - The agent that will execute the task
|
|
95
|
+
* @param task - Task description
|
|
96
|
+
* @param inferenceUrl - Optional URL of the inference endpoint (default: localhost)
|
|
97
|
+
* @returns Final task result
|
|
98
|
+
*/
|
|
99
|
+
async runAgentTask(agentId, task, inferenceUrl) {
|
|
100
|
+
return this.rpc.call("tenzro_runAgentTask", [
|
|
101
|
+
{ agent_id: agentId, task, inference_url: inferenceUrl },
|
|
102
|
+
]);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Create a swarm of member agents under an orchestrator.
|
|
106
|
+
* @param orchestratorId - The orchestrator agent's ID
|
|
107
|
+
* @param members - Array of member specs (name + capabilities)
|
|
108
|
+
* @param options - Optional swarm configuration
|
|
109
|
+
* @returns Swarm ID and orchestrator ID
|
|
110
|
+
*/
|
|
111
|
+
async createSwarm(orchestratorId, members, options) {
|
|
112
|
+
return this.rpc.call("tenzro_createSwarm", [
|
|
113
|
+
{ orchestrator_id: orchestratorId, members, ...options },
|
|
114
|
+
]);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Get the current status of a swarm.
|
|
118
|
+
* @param swarmId - The swarm's ID
|
|
119
|
+
* @returns Swarm status including member statuses
|
|
120
|
+
*/
|
|
121
|
+
async getSwarmStatus(swarmId) {
|
|
122
|
+
return this.rpc.call("tenzro_getSwarmStatus", [
|
|
123
|
+
{ swarm_id: swarmId },
|
|
124
|
+
]);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Terminate a swarm and all its member agents.
|
|
128
|
+
* @param swarmId - The swarm's ID
|
|
129
|
+
* @returns Confirmation with swarm_id and status "terminated"
|
|
130
|
+
*/
|
|
131
|
+
async terminateSwarm(swarmId) {
|
|
132
|
+
return this.rpc.call("tenzro_terminateSwarm", [
|
|
133
|
+
{ swarm_id: swarmId },
|
|
134
|
+
]);
|
|
135
|
+
}
|
|
136
|
+
// ─── AgentKit: Template-based agent lifecycle ─────────────────────────────
|
|
137
|
+
/**
|
|
138
|
+
* Spawn a new agent from a registered template.
|
|
139
|
+
* @param templateId - The template to instantiate
|
|
140
|
+
* @param displayName - Optional human-readable name for the spawned agent
|
|
141
|
+
* @param context - Optional key-value context passed to the agent at boot
|
|
142
|
+
* @returns Spawned agent info with agent_id, template_id, name, and status
|
|
143
|
+
*/
|
|
144
|
+
async spawnAgentTemplate(templateId, displayName, context) {
|
|
145
|
+
return this.rpc.call("tenzro_spawnAgentTemplate", [
|
|
146
|
+
{ template_id: templateId, display_name: displayName, context },
|
|
147
|
+
]);
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Run an already-spawned template agent through its task loop.
|
|
151
|
+
* @param agentId - The agent to run
|
|
152
|
+
* @param maxIterations - Optional cap on loop iterations (default: server-side default)
|
|
153
|
+
* @param dryRun - If true, simulate execution without side effects
|
|
154
|
+
* @returns Execution report with iterations, status, result, and duration
|
|
155
|
+
*/
|
|
156
|
+
async runAgentTemplate(agentId, maxIterations, dryRun) {
|
|
157
|
+
return this.rpc.call("tenzro_runAgentTemplate", [
|
|
158
|
+
{ agent_id: agentId, max_iterations: maxIterations, dry_run: dryRun },
|
|
159
|
+
]);
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Download a template's full definition for offline inspection or forking.
|
|
163
|
+
* @param templateId - The template to download
|
|
164
|
+
* @returns Full agent template
|
|
165
|
+
*/
|
|
166
|
+
async downloadAgentTemplate(templateId) {
|
|
167
|
+
return this.rpc.call("tenzro_downloadAgentTemplate", [
|
|
168
|
+
{ template_id: templateId },
|
|
169
|
+
]);
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Update a registered agent template (must be the creator).
|
|
173
|
+
* @param templateId - The template to update
|
|
174
|
+
* @param params - Fields to update (partial — only provided fields are changed)
|
|
175
|
+
* @returns Updated agent template
|
|
176
|
+
*/
|
|
177
|
+
async updateAgentTemplate(templateId, params) {
|
|
178
|
+
return this.rpc.call("tenzro_updateAgentTemplate", [
|
|
179
|
+
{ template_id: templateId, ...params },
|
|
180
|
+
]);
|
|
181
|
+
}
|
|
182
|
+
// ─── Discovery & Lifecycle ──────────────────────────────────────────────────
|
|
183
|
+
/**
|
|
184
|
+
* Discover available models with optional filters.
|
|
185
|
+
* @param options - Optional filters: modality, servingOnly, query
|
|
186
|
+
* @returns Array of discovered models
|
|
187
|
+
*/
|
|
188
|
+
async discoverModels(options) {
|
|
189
|
+
return this.rpc.call("tenzro_discoverModels", [
|
|
190
|
+
{
|
|
191
|
+
modality: options?.modality,
|
|
192
|
+
serving_only: options?.servingOnly,
|
|
193
|
+
query: options?.query,
|
|
194
|
+
},
|
|
195
|
+
]);
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Discover available agents with optional capability filter.
|
|
199
|
+
* @param capability - Optional capability to filter by
|
|
200
|
+
* @returns Array of discovered agents
|
|
201
|
+
*/
|
|
202
|
+
async discoverAgents(capability) {
|
|
203
|
+
return this.rpc.call("tenzro_discoverAgents", [{ capability }]);
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Spawn an agent with a specific skill attached.
|
|
207
|
+
* @param parentId - The parent agent's ID
|
|
208
|
+
* @param name - Name for the new agent
|
|
209
|
+
* @param skillId - Skill to attach to the agent
|
|
210
|
+
* @param capabilities - Optional list of capabilities
|
|
211
|
+
* @returns Spawned agent info
|
|
212
|
+
*/
|
|
213
|
+
async spawnAgentWithSkill(parentId, name, skillId, capabilities) {
|
|
214
|
+
return this.rpc.call("tenzro_spawnAgentWithSkill", [
|
|
215
|
+
{
|
|
216
|
+
parent_id: parentId,
|
|
217
|
+
name,
|
|
218
|
+
skill_id: skillId,
|
|
219
|
+
capabilities,
|
|
220
|
+
},
|
|
221
|
+
]);
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Fund an agent's wallet.
|
|
225
|
+
* @param agentId - The agent to fund
|
|
226
|
+
* @param fromAddress - Source address for the funds
|
|
227
|
+
* @param amountTnzo - Amount of TNZO to transfer
|
|
228
|
+
* @returns Funding result
|
|
229
|
+
*/
|
|
230
|
+
async fundAgent(agentId, fromAddress, amountTnzo) {
|
|
231
|
+
return this.rpc.call("tenzro_fundAgent", [
|
|
232
|
+
{
|
|
233
|
+
agent_id: agentId,
|
|
234
|
+
from_address: fromAddress,
|
|
235
|
+
amount_tnzo: amountTnzo,
|
|
236
|
+
},
|
|
237
|
+
]);
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Swap tokens for an agent.
|
|
241
|
+
* @param agentId - The agent performing the swap
|
|
242
|
+
* @param fromToken - Source token identifier
|
|
243
|
+
* @param toToken - Destination token identifier
|
|
244
|
+
* @param amount - Amount to swap
|
|
245
|
+
* @param chain - Optional chain for the swap
|
|
246
|
+
* @returns Swap result
|
|
247
|
+
*/
|
|
248
|
+
async swapToken(agentId, fromToken, toToken, amount, chain) {
|
|
249
|
+
return this.rpc.call("tenzro_swapToken", [
|
|
250
|
+
{
|
|
251
|
+
agent_id: agentId,
|
|
252
|
+
from_token: fromToken,
|
|
253
|
+
to_token: toToken,
|
|
254
|
+
amount,
|
|
255
|
+
chain,
|
|
256
|
+
},
|
|
257
|
+
]);
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Run the full agent payment pipeline for inference.
|
|
261
|
+
* @param agentId - The agent paying for inference
|
|
262
|
+
* @param modelId - The model to use
|
|
263
|
+
* @param prompt - The prompt to send
|
|
264
|
+
* @param maxTokens - Optional max tokens for the response
|
|
265
|
+
* @returns Inference result with payment details
|
|
266
|
+
*/
|
|
267
|
+
async agentPayForInference(agentId, modelId, prompt, maxTokens) {
|
|
268
|
+
return this.rpc.call("tenzro_agentPayForInference", [
|
|
269
|
+
{
|
|
270
|
+
agent_id: agentId,
|
|
271
|
+
model_id: modelId,
|
|
272
|
+
prompt,
|
|
273
|
+
max_tokens: maxTokens,
|
|
274
|
+
},
|
|
275
|
+
]);
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Set the gas policy for an agent's on-chain operations.
|
|
279
|
+
* @param agentId - The agent identifier
|
|
280
|
+
* @param policy - Gas policy configuration
|
|
281
|
+
* @returns Updated gas policy
|
|
282
|
+
*/
|
|
283
|
+
async setGasPolicy(agentId, policy) {
|
|
284
|
+
return this.rpc.call("tenzro_setAgentGasPolicy", [
|
|
285
|
+
{ agent_id: agentId, ...policy },
|
|
286
|
+
]);
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Get the current gas policy for an agent.
|
|
290
|
+
* @param agentId - The agent identifier
|
|
291
|
+
* @returns Current gas policy
|
|
292
|
+
*/
|
|
293
|
+
async getGasPolicy(agentId) {
|
|
294
|
+
return this.rpc.call("tenzro_getAgentGasPolicy", [
|
|
295
|
+
{ agent_id: agentId },
|
|
296
|
+
]);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
exports.AgentClient = AgentClient;
|
|
300
|
+
//# sourceMappingURL=agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.js","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":";;;AAkBA,0DAA0D;AAC1D,SAAS,YAAY;IACnB,OAAO,sCAAsC,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE;QACnE,MAAM,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;QACjC,MAAM,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC;QAC1C,OAAO,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IACxB,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;GAGG;AACH,MAAa,WAAW;IACF;IAApB,YAAoB,GAAc;QAAd,QAAG,GAAH,GAAG,CAAW;IAAG,CAAC;IAEtC;;;;;;OAMG;IACH,KAAK,CAAC,QAAQ,CACZ,OAAe,EACf,IAAY,EACZ,YAAsB;QAEtB,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAwB,sBAAsB,EAAE;YAClE;gBACE,QAAQ,EAAE,OAAO;gBACjB,IAAI;gBACJ,YAAY;aACb;SACF,CAAC,CAAC;IACL,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,WAAW,CACf,OAAe,EACf,OA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AAe,EACf,SAAiB,EACjB,OAAe,EACf,MAAc,EACd,KAAc;QAEd,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,kBAAkB,EAAE;YACvC;gBACE,QAAQ,EAAE,OAAO;gBACjB,UAAU,EAAE,SAAS;gBACrB,QAAQ,EAAE,OAAO;gBACjB,MAAM;gBACN,KAAK;aACN;SACF,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,oBAAoB,CACxB,OAAe,EACf,OAAe,EACf,MAAc,EACd,SAAkB;QAElB,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,6BAA6B,EAAE;YAClD;gBACE,QAAQ,EAAE,OAAO;gBACjB,QAAQ,EAAE,OAAO;gBACjB,MAAM;gBACN,UAAU,EAAE,SAAS;aACtB;SACF,CAAC,CAAC;IACL,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,YAAY,CAAC,OAAe,EAAE,MAAiB;QACnD,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAY,0BAA0B,EAAE;YAC1D,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,MAAM,EAAE;SACjC,CAAC,CAAC;IACL,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,YAAY,CAAC,OAAe;QAChC,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAY,0BAA0B,EAAE;YAC1D,EAAE,QAAQ,EAAE,OAAO,EAAE;SACtB,CAAC,CAAC;IACL,CAAC;CACF;AAvWD,kCAuWC"}
|
package/dist/ap2.d.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { RpcClient } from './rpc';
|
|
2
|
+
import type { Ap2Session, Ap2Authorization, PaymentReceipt, CancelResult } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Client for the AP2 (Agentic Payment Protocol).
|
|
5
|
+
* Enables agents to establish payment sessions with providers,
|
|
6
|
+
* authorize individual payments, and manage session lifecycle.
|
|
7
|
+
*/
|
|
8
|
+
export declare class Ap2Client {
|
|
9
|
+
private readonly rpc;
|
|
10
|
+
constructor(rpc: RpcClient);
|
|
11
|
+
/**
|
|
12
|
+
* Create a new AP2 payment session between an agent and a provider.
|
|
13
|
+
* @param agentDid - DID of the agent initiating the session
|
|
14
|
+
* @param providerDid - DID of the service provider
|
|
15
|
+
* @param service - Service identifier (e.g., model ID or endpoint)
|
|
16
|
+
* @param maxAmount - Maximum authorized spend for this session (decimal string)
|
|
17
|
+
* @param asset - Asset to use for payments (default: "TNZO")
|
|
18
|
+
* @returns Created AP2 session
|
|
19
|
+
*/
|
|
20
|
+
createSession(agentDid: string, providerDid: string, service: string, maxAmount: string, asset?: string): Promise<Ap2Session>;
|
|
21
|
+
/**
|
|
22
|
+
* Authorize a payment within an existing AP2 session.
|
|
23
|
+
* @param sessionId - The session to authorize against
|
|
24
|
+
* @param amount - Amount to authorize (decimal string)
|
|
25
|
+
* @returns Payment authorization
|
|
26
|
+
*/
|
|
27
|
+
authorizePayment(sessionId: string, amount: string): Promise<Ap2Authorization>;
|
|
28
|
+
/**
|
|
29
|
+
* Execute a previously authorized payment.
|
|
30
|
+
* @param sessionId - The session containing the authorization
|
|
31
|
+
* @param authorizationId - The authorization to execute
|
|
32
|
+
* @returns Payment receipt
|
|
33
|
+
*/
|
|
34
|
+
executePayment(sessionId: string, authorizationId: string): Promise<PaymentReceipt>;
|
|
35
|
+
/**
|
|
36
|
+
* Cancel an active AP2 session.
|
|
37
|
+
* @param sessionId - The session to cancel
|
|
38
|
+
* @returns Cancellation result with optional refund info
|
|
39
|
+
*/
|
|
40
|
+
cancelSession(sessionId: string): Promise<CancelResult>;
|
|
41
|
+
/**
|
|
42
|
+
* Get details of an AP2 session.
|
|
43
|
+
* @param sessionId - The session identifier
|
|
44
|
+
* @returns Session details
|
|
45
|
+
*/
|
|
46
|
+
getSession(sessionId: string): Promise<Ap2Session>;
|
|
47
|
+
/**
|
|
48
|
+
* List all AP2 sessions for a given agent.
|
|
49
|
+
* @param agentDid - The agent's DID
|
|
50
|
+
* @returns Array of AP2 sessions
|
|
51
|
+
*/
|
|
52
|
+
listAgentSessions(agentDid: string): Promise<Ap2Session[]>;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=ap2.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ap2.d.ts","sourceRoot":"","sources":["../src/ap2.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,KAAK,EACV,UAAU,EACV,gBAAgB,EAChB,cAAc,EACd,YAAY,EACb,MAAM,SAAS,CAAC;AAEjB;;;;GAIG;AACH,qBAAa,SAAS;IACR,OAAO,CAAC,QAAQ,CAAC,GAAG;gBAAH,GAAG,EAAE,SAAS;IAE3C;;;;;;;;OAQG;IACG,aAAa,CACjB,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EACjB,KAAK,GAAE,MAAe,GACrB,OAAO,CAAC,UAAU,CAAC;IAYtB;;;;;OAKG;IACG,gBAAgB,CACpB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,gBAAgB,CAAC;IAM5B;;;;;OAKG;IACG,cAAc,CAClB,SAAS,EAAE,MAAM,EACjB,eAAe,EAAE,MAAM,GACtB,OAAO,CAAC,cAAc,CAAC;IAM1B;;;;OAIG;IACG,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAM7D;;;;OAIG;IACG,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAMxD;;;;OAIG;IACG,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;CAKjE"}
|
package/dist/ap2.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Ap2Client = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Client for the AP2 (Agentic Payment Protocol).
|
|
6
|
+
* Enables agents to establish payment sessions with providers,
|
|
7
|
+
* authorize individual payments, and manage session lifecycle.
|
|
8
|
+
*/
|
|
9
|
+
class Ap2Client {
|
|
10
|
+
rpc;
|
|
11
|
+
constructor(rpc) {
|
|
12
|
+
this.rpc = rpc;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Create a new AP2 payment session between an agent and a provider.
|
|
16
|
+
* @param agentDid - DID of the agent initiating the session
|
|
17
|
+
* @param providerDid - DID of the service provider
|
|
18
|
+
* @param service - Service identifier (e.g., model ID or endpoint)
|
|
19
|
+
* @param maxAmount - Maximum authorized spend for this session (decimal string)
|
|
20
|
+
* @param asset - Asset to use for payments (default: "TNZO")
|
|
21
|
+
* @returns Created AP2 session
|
|
22
|
+
*/
|
|
23
|
+
async createSession(agentDid, providerDid, service, maxAmount, asset = 'TNZO') {
|
|
24
|
+
return this.rpc.call('tenzro_ap2CreateSession', [
|
|
25
|
+
{
|
|
26
|
+
agent_did: agentDid,
|
|
27
|
+
provider_did: providerDid,
|
|
28
|
+
service,
|
|
29
|
+
max_amount: maxAmount,
|
|
30
|
+
asset,
|
|
31
|
+
},
|
|
32
|
+
]);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Authorize a payment within an existing AP2 session.
|
|
36
|
+
* @param sessionId - The session to authorize against
|
|
37
|
+
* @param amount - Amount to authorize (decimal string)
|
|
38
|
+
* @returns Payment authorization
|
|
39
|
+
*/
|
|
40
|
+
async authorizePayment(sessionId, amount) {
|
|
41
|
+
return this.rpc.call('tenzro_ap2AuthorizePayment', [
|
|
42
|
+
{ session_id: sessionId, amount },
|
|
43
|
+
]);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Execute a previously authorized payment.
|
|
47
|
+
* @param sessionId - The session containing the authorization
|
|
48
|
+
* @param authorizationId - The authorization to execute
|
|
49
|
+
* @returns Payment receipt
|
|
50
|
+
*/
|
|
51
|
+
async executePayment(sessionId, authorizationId) {
|
|
52
|
+
return this.rpc.call('tenzro_ap2ExecutePayment', [
|
|
53
|
+
{ session_id: sessionId, authorization_id: authorizationId },
|
|
54
|
+
]);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Cancel an active AP2 session.
|
|
58
|
+
* @param sessionId - The session to cancel
|
|
59
|
+
* @returns Cancellation result with optional refund info
|
|
60
|
+
*/
|
|
61
|
+
async cancelSession(sessionId) {
|
|
62
|
+
return this.rpc.call('tenzro_ap2CancelSession', [
|
|
63
|
+
{ session_id: sessionId },
|
|
64
|
+
]);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Get details of an AP2 session.
|
|
68
|
+
* @param sessionId - The session identifier
|
|
69
|
+
* @returns Session details
|
|
70
|
+
*/
|
|
71
|
+
async getSession(sessionId) {
|
|
72
|
+
return this.rpc.call('tenzro_ap2GetSession', [
|
|
73
|
+
{ session_id: sessionId },
|
|
74
|
+
]);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* List all AP2 sessions for a given agent.
|
|
78
|
+
* @param agentDid - The agent's DID
|
|
79
|
+
* @returns Array of AP2 sessions
|
|
80
|
+
*/
|
|
81
|
+
async listAgentSessions(agentDid) {
|
|
82
|
+
return this.rpc.call('tenzro_ap2ListAgentSessions', [
|
|
83
|
+
{ agent_did: agentDid },
|
|
84
|
+
]);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
exports.Ap2Client = Ap2Client;
|
|
88
|
+
//# sourceMappingURL=ap2.js.map
|
package/dist/ap2.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ap2.js","sourceRoot":"","sources":["../src/ap2.ts"],"names":[],"mappings":";;;AAQA;;;;GAIG;AACH,MAAa,SAAS;IACS;IAA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,IAAI,CAAC,GAAG,CAAC,IAAI,CAAe,6BAA6B,EAAE;YAChE,EAAE,SAAS,EAAE,QAAQ,EAAE;SACxB,CAAC,CAAC;IACL,CAAC;CACF;AA5FD,8BA4FC"}
|
package/dist/app.d.ts
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { TenzroClient } from "./client";
|
|
2
|
+
/** Master wallet information derived from the developer's private key. */
|
|
3
|
+
export interface MasterWallet {
|
|
4
|
+
/** Hex-encoded master wallet address (with 0x prefix) */
|
|
5
|
+
address: string;
|
|
6
|
+
/** Hex-encoded public key */
|
|
7
|
+
publicKey: string;
|
|
8
|
+
}
|
|
9
|
+
/** A user sub-wallet created and funded by the master wallet. */
|
|
10
|
+
export interface UserWallet {
|
|
11
|
+
/** Hex-encoded user wallet address (with 0x prefix) */
|
|
12
|
+
address: string;
|
|
13
|
+
/** Human-readable label */
|
|
14
|
+
label: string;
|
|
15
|
+
/** ISO-8601 creation timestamp */
|
|
16
|
+
createdAt: string;
|
|
17
|
+
/** Optional spending policy applied to this wallet */
|
|
18
|
+
spendingPolicy?: SpendingPolicy;
|
|
19
|
+
}
|
|
20
|
+
/** Result of funding a user wallet. */
|
|
21
|
+
export interface FundResult {
|
|
22
|
+
/** Transaction hash of the funding transfer */
|
|
23
|
+
txHash: string;
|
|
24
|
+
/** Amount transferred in wei */
|
|
25
|
+
amount: bigint;
|
|
26
|
+
}
|
|
27
|
+
/** Spending limits enforced on a user wallet. */
|
|
28
|
+
export interface SpendingPolicy {
|
|
29
|
+
/** Maximum amount (wei) per 24-hour rolling window */
|
|
30
|
+
dailyLimit: bigint;
|
|
31
|
+
/** Maximum amount (wei) per single transaction */
|
|
32
|
+
perTxLimit: bigint;
|
|
33
|
+
/** Amount already spent in the current daily window */
|
|
34
|
+
dailySpent: bigint;
|
|
35
|
+
}
|
|
36
|
+
/** A scoped session key with temporary, limited permissions. */
|
|
37
|
+
export interface SessionKey {
|
|
38
|
+
/** Unique session identifier */
|
|
39
|
+
sessionId: string;
|
|
40
|
+
/** ISO-8601 expiry timestamp */
|
|
41
|
+
expiresAt: string;
|
|
42
|
+
/** Allowed operation names (e.g. "transfer", "inference") */
|
|
43
|
+
operations: string[];
|
|
44
|
+
}
|
|
45
|
+
/** Aggregated usage statistics for the master wallet. */
|
|
46
|
+
export interface UsageStats {
|
|
47
|
+
/** Total gas spent across all sponsored transactions (wei) */
|
|
48
|
+
totalGasSpent: bigint;
|
|
49
|
+
/** Estimated total cost of inference requests (TNZO) */
|
|
50
|
+
totalInferenceCost: number;
|
|
51
|
+
/** Total bridge fees paid (wei) */
|
|
52
|
+
totalBridgeFees: bigint;
|
|
53
|
+
/** Number of user wallets created */
|
|
54
|
+
userCount: number;
|
|
55
|
+
/** Total number of sponsored transactions */
|
|
56
|
+
transactionCount: number;
|
|
57
|
+
}
|
|
58
|
+
/** Result of a sponsored inference request. */
|
|
59
|
+
export interface InferenceResult {
|
|
60
|
+
/** Model output text */
|
|
61
|
+
output: string;
|
|
62
|
+
/** Number of tokens generated */
|
|
63
|
+
tokens: number;
|
|
64
|
+
/** Estimated cost in TNZO */
|
|
65
|
+
cost: number;
|
|
66
|
+
/** Model used */
|
|
67
|
+
modelId: string;
|
|
68
|
+
}
|
|
69
|
+
/** Result of a sponsored agent registration. */
|
|
70
|
+
export interface AgentResult {
|
|
71
|
+
/** Registered agent ID */
|
|
72
|
+
agentId: string;
|
|
73
|
+
/** Agent's wallet address */
|
|
74
|
+
walletAddress: string;
|
|
75
|
+
}
|
|
76
|
+
/** Result of a sponsored bridge transfer. */
|
|
77
|
+
export interface BridgeResult {
|
|
78
|
+
/** Bridge transaction hash */
|
|
79
|
+
txHash: string;
|
|
80
|
+
/** Current status */
|
|
81
|
+
status: string;
|
|
82
|
+
}
|
|
83
|
+
/** Result of a sponsored task posting. */
|
|
84
|
+
export interface TaskResult {
|
|
85
|
+
/** Posted task ID */
|
|
86
|
+
taskId: string;
|
|
87
|
+
}
|
|
88
|
+
/** Result of a sponsored transaction. */
|
|
89
|
+
export interface TxResult {
|
|
90
|
+
/** Transaction hash */
|
|
91
|
+
txHash: string;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Application client -- the primary interface for developers building on Tenzro.
|
|
95
|
+
*
|
|
96
|
+
* Wraps a master wallet and provides methods to:
|
|
97
|
+
* - Create and fund user wallets
|
|
98
|
+
* - Sponsor gas for user transactions (paymaster)
|
|
99
|
+
* - Manage spending policies and session keys
|
|
100
|
+
* - Track usage and costs
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```ts
|
|
104
|
+
* const app = await AppClient.create("https://rpc.tenzro.network", "your-master-wallet-private-key");
|
|
105
|
+
*
|
|
106
|
+
* // Create a user wallet (funded from master)
|
|
107
|
+
* const user = await app.createUserWallet("alice", 100_000_000_000_000_000n);
|
|
108
|
+
*
|
|
109
|
+
* // Sponsor an inference request
|
|
110
|
+
* const result = await app.sponsorInference(user.address, "gemma3-270m", "Hello world");
|
|
111
|
+
*
|
|
112
|
+
* // Check usage
|
|
113
|
+
* const stats = await app.getUsageStats();
|
|
114
|
+
* console.log("Total gas spent:", stats.totalGasSpent);
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
export declare class AppClient {
|
|
118
|
+
private rpc;
|
|
119
|
+
private tenzroClient;
|
|
120
|
+
private masterWalletInfo;
|
|
121
|
+
private state;
|
|
122
|
+
private constructor();
|
|
123
|
+
/**
|
|
124
|
+
* Create a new AppClient with a master wallet private key.
|
|
125
|
+
*
|
|
126
|
+
* The private key should be the hex-encoded Ed25519 or Secp256k1 key that
|
|
127
|
+
* controls the developer's master wallet.
|
|
128
|
+
*/
|
|
129
|
+
static create(rpcUrl: string, masterPrivateKey: string): Promise<AppClient>;
|
|
130
|
+
/**
|
|
131
|
+
* Connect using an API key that resolves to a master wallet on the server.
|
|
132
|
+
*/
|
|
133
|
+
static fromApiKey(rpcUrl: string, apiKey: string): Promise<AppClient>;
|
|
134
|
+
/**
|
|
135
|
+
* Create a sub-wallet for a user, funded from the master wallet.
|
|
136
|
+
*
|
|
137
|
+
* 1. Creates a new keypair via `tenzro_createWallet`
|
|
138
|
+
* 2. Transfers `initialFundingWei` TNZO from master to the new wallet
|
|
139
|
+
* 3. Tracks the user locally for policy enforcement
|
|
140
|
+
*/
|
|
141
|
+
createUserWallet(label: string, initialFundingWei: bigint): Promise<UserWallet>;
|
|
142
|
+
/** Fund an existing user wallet from the master wallet. */
|
|
143
|
+
fundUserWallet(userAddress: string, amountWei: bigint): Promise<FundResult>;
|
|
144
|
+
/** List all user wallets created by this app. */
|
|
145
|
+
listUserWallets(): Promise<UserWallet[]>;
|
|
146
|
+
/**
|
|
147
|
+
* Set spending limits for a user wallet.
|
|
148
|
+
* Policies are enforced locally before submitting sponsored transactions.
|
|
149
|
+
*/
|
|
150
|
+
setUserLimits(userAddress: string, dailyLimit: bigint, perTxLimit: bigint): Promise<SpendingPolicy>;
|
|
151
|
+
/** Create a session key for a user with scoped permissions and expiry. */
|
|
152
|
+
createSessionKey(userAddress: string, durationSecs: number, allowedOps: string[]): Promise<SessionKey>;
|
|
153
|
+
/**
|
|
154
|
+
* Send a transaction on behalf of a user (master pays gas).
|
|
155
|
+
*/
|
|
156
|
+
sponsorTransaction(userAddress: string, to: string, amountWei: bigint): Promise<TxResult>;
|
|
157
|
+
/**
|
|
158
|
+
* Run inference on behalf of a user (master pays).
|
|
159
|
+
*/
|
|
160
|
+
sponsorInference(userAddress: string, modelId: string, message: string): Promise<InferenceResult>;
|
|
161
|
+
/**
|
|
162
|
+
* Spawn an agent on behalf of a user (master pays).
|
|
163
|
+
*/
|
|
164
|
+
sponsorAgent(userAddress: string, agentName: string, capabilities: string[]): Promise<AgentResult>;
|
|
165
|
+
/**
|
|
166
|
+
* Bridge tokens on behalf of a user (master pays bridge fees).
|
|
167
|
+
*/
|
|
168
|
+
sponsorBridge(userAddress: string, token: string, fromChain: string, toChain: string, amount: string, recipient: string): Promise<BridgeResult>;
|
|
169
|
+
/**
|
|
170
|
+
* Post a task to the marketplace on behalf of a user (master pays budget).
|
|
171
|
+
*/
|
|
172
|
+
sponsorTask(userAddress: string, title: string, description: string, taskType: string, budgetWei: bigint): Promise<TaskResult>;
|
|
173
|
+
/** Get master wallet balance in wei. */
|
|
174
|
+
getMasterBalance(): Promise<bigint>;
|
|
175
|
+
/**
|
|
176
|
+
* Get aggregated usage statistics for this app instance.
|
|
177
|
+
* Statistics are tracked locally since the AppClient was created.
|
|
178
|
+
*/
|
|
179
|
+
getUsageStats(): Promise<UsageStats>;
|
|
180
|
+
/** Returns the master wallet information. */
|
|
181
|
+
get masterWallet(): MasterWallet;
|
|
182
|
+
/** Get the underlying TenzroClient for advanced operations. */
|
|
183
|
+
get client(): TenzroClient;
|
|
184
|
+
private enforceSpendingPolicy;
|
|
185
|
+
}
|
|
186
|
+
//# sourceMappingURL=app.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAQxC,0EAA0E;AAC1E,MAAM,WAAW,YAAY;IAC3B,yDAAyD;IACzD,OAAO,EAAE,MAAM,CAAC;IAChB,6BAA6B;IAC7B,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,iEAAiE;AACjE,MAAM,WAAW,UAAU;IACzB,uDAAuD;IACvD,OAAO,EAAE,MAAM,CAAC;IAChB,2BAA2B;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,kCAAkC;IAClC,SAAS,EAAE,MAAM,CAAC;IAClB,sDAAsD;IACtD,cAAc,CAAC,EAAE,cAAc,CAAC;CACjC;AAED,uCAAuC;AACvC,MAAM,WAAW,UAAU;IACzB,+CAA+C;IAC/C,MAAM,EAAE,MAAM,CAAC;IACf,gCAAgC;IAChC,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,iDAAiD;AACjD,MAAM,WAAW,cAAc;IAC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