@agentxv2/sdk 0.3.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 +195 -0
- package/dist/a2a/a2a.d.ts +37 -0
- package/dist/a2a/a2a.d.ts.map +1 -0
- package/dist/a2a/a2a.js +252 -0
- package/dist/a2a/a2a.js.map +1 -0
- package/dist/a2a/index.d.ts +4 -0
- package/dist/a2a/index.d.ts.map +1 -0
- package/dist/a2a/index.js +4 -0
- package/dist/a2a/index.js.map +1 -0
- package/dist/agent/agent-runner.d.ts +124 -0
- package/dist/agent/agent-runner.d.ts.map +1 -0
- package/dist/agent/agent-runner.js +249 -0
- package/dist/agent/agent-runner.js.map +1 -0
- package/dist/agent/index.d.ts +3 -0
- package/dist/agent/index.d.ts.map +1 -0
- package/dist/agent/index.js +3 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/config/config.d.ts +31 -0
- package/dist/config/config.d.ts.map +1 -0
- package/dist/config/config.js +95 -0
- package/dist/config/config.js.map +1 -0
- package/dist/config/index.d.ts +4 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +4 -0
- package/dist/config/index.js.map +1 -0
- package/dist/core/crypto.d.ts +62 -0
- package/dist/core/crypto.d.ts.map +1 -0
- package/dist/core/crypto.js +291 -0
- package/dist/core/crypto.js.map +1 -0
- package/dist/core/index.d.ts +3 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +4 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/types.d.ts +296 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +30 -0
- package/dist/core/types.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +32 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/connector.d.ts +43 -0
- package/dist/mcp/connector.d.ts.map +1 -0
- package/dist/mcp/connector.js +79 -0
- package/dist/mcp/connector.js.map +1 -0
- package/dist/mcp/index.d.ts +4 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +4 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/react/index.d.ts +4 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +3 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/useAgentRunner.d.ts +16 -0
- package/dist/react/useAgentRunner.d.ts.map +1 -0
- package/dist/react/useAgentRunner.js +204 -0
- package/dist/react/useAgentRunner.js.map +1 -0
- package/dist/registry/agent-registry.d.ts +52 -0
- package/dist/registry/agent-registry.d.ts.map +1 -0
- package/dist/registry/agent-registry.js +221 -0
- package/dist/registry/agent-registry.js.map +1 -0
- package/dist/registry/index.d.ts +7 -0
- package/dist/registry/index.d.ts.map +1 -0
- package/dist/registry/index.js +6 -0
- package/dist/registry/index.js.map +1 -0
- package/dist/registry/ipfs-fetcher.d.ts +39 -0
- package/dist/registry/ipfs-fetcher.d.ts.map +1 -0
- package/dist/registry/ipfs-fetcher.js +139 -0
- package/dist/registry/ipfs-fetcher.js.map +1 -0
- package/dist/reputation/index.d.ts +4 -0
- package/dist/reputation/index.d.ts.map +1 -0
- package/dist/reputation/index.js +4 -0
- package/dist/reputation/index.js.map +1 -0
- package/dist/reputation/reputation.d.ts +26 -0
- package/dist/reputation/reputation.d.ts.map +1 -0
- package/dist/reputation/reputation.js +113 -0
- package/dist/reputation/reputation.js.map +1 -0
- package/dist/subscription/agent-x402.d.ts +33 -0
- package/dist/subscription/agent-x402.d.ts.map +1 -0
- package/dist/subscription/agent-x402.js +144 -0
- package/dist/subscription/agent-x402.js.map +1 -0
- package/dist/subscription/index.d.ts +6 -0
- package/dist/subscription/index.d.ts.map +1 -0
- package/dist/subscription/index.js +5 -0
- package/dist/subscription/index.js.map +1 -0
- package/dist/subscription/subscription.d.ts +67 -0
- package/dist/subscription/subscription.d.ts.map +1 -0
- package/dist/subscription/subscription.js +346 -0
- package/dist/subscription/subscription.js.map +1 -0
- package/package.json +69 -0
package/README.md
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
# @agentx/sdk v0.2.0
|
|
2
|
+
|
|
3
|
+
**Decentralized AI Agent Platform SDK** — E2E encryption, on-chain subscriptions, MCP tool execution.
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
Agent = Prompt + Skills[] + MCP
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @agentx/sdk
|
|
13
|
+
# or
|
|
14
|
+
pnpm add @agentx/sdk
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
### Peer Dependencies
|
|
18
|
+
|
|
19
|
+
| Package | Version | Required |
|
|
20
|
+
|---------|---------|----------|
|
|
21
|
+
| `react` | ^18 or ^19 | yes |
|
|
22
|
+
| `wagmi` | ^2.0 | optional (React hooks only) |
|
|
23
|
+
| `@tanstack/react-query` | ^5.0 | optional (React hooks only) |
|
|
24
|
+
| `viem` | ^2.0 | optional (chain reader only) |
|
|
25
|
+
|
|
26
|
+
## Quick Start
|
|
27
|
+
|
|
28
|
+
### 1. Use an Agent (End-to-End Encrypted)
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
import { AgentRunner } from '@agentx/sdk'
|
|
32
|
+
import type { OnChainReader, WalletSigner } from '@agentx/sdk'
|
|
33
|
+
|
|
34
|
+
// Implement these interfaces with your viem/wagmi setup
|
|
35
|
+
const reader: OnChainReader = { /* ... */ }
|
|
36
|
+
const wallet: WalletSigner = { /* ... */ }
|
|
37
|
+
|
|
38
|
+
const runner = new AgentRunner({ reader, wallet })
|
|
39
|
+
const ctx = await runner.useAgent(42)
|
|
40
|
+
|
|
41
|
+
// Inject into your LLM:
|
|
42
|
+
// ctx.prompt → system prompt
|
|
43
|
+
// ctx.skills → tools with execute() method
|
|
44
|
+
// ctx.mcp → MCP server connection info
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### 2. React Hook (with wagmi)
|
|
48
|
+
|
|
49
|
+
```tsx
|
|
50
|
+
import { useAgentRunner } from '@agentx/sdk/react'
|
|
51
|
+
|
|
52
|
+
function ChatPage({ agentId }: { agentId: number }) {
|
|
53
|
+
const { ctx, isLoading, error, refetch } = useAgentRunner({ agentId })
|
|
54
|
+
|
|
55
|
+
if (isLoading) return <div>Loading agent...</div>
|
|
56
|
+
if (error) return <div>Error: {error.message}</div>
|
|
57
|
+
|
|
58
|
+
// ctx.prompt → inject as LLM system prompt
|
|
59
|
+
// ctx.skills → call skill.execute({ ... }) for tool invocations
|
|
60
|
+
return <ChatInterface prompt={ctx!.prompt} skills={ctx!.skills} />
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### 3. Publish an Agent
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
import { generateAesKey, encryptPayload, packAgentForPublish } from '@agentx/sdk'
|
|
68
|
+
|
|
69
|
+
const privatePayload = { prompt: '...', skills: [...], mcp: { type: 'http', url: '' } }
|
|
70
|
+
|
|
71
|
+
// AES-256-GCM encrypt
|
|
72
|
+
const aesKey = generateAesKey()
|
|
73
|
+
const encrypted = encryptPayload(privatePayload, aesKey)
|
|
74
|
+
|
|
75
|
+
// Pack for on-chain registration
|
|
76
|
+
const packResult = packAgentForPublish(agentPayload, publicKey, aesKey)
|
|
77
|
+
// → packResult.aesKeyHex, packResult.eciesEncryptedKeyHex
|
|
78
|
+
|
|
79
|
+
// Upload encrypted.data to IPFS, store aesKeyHex as NFT metadata on-chain
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Architecture
|
|
83
|
+
|
|
84
|
+
```
|
|
85
|
+
┌────────────────────────────────────────────────────┐
|
|
86
|
+
│ @agentx/sdk │
|
|
87
|
+
├──────────┬──────────┬──────────┬──────────────────┤
|
|
88
|
+
│ Core │ Agent │ MCP │ React │
|
|
89
|
+
│ crypto │ Runner │ Connector│ useAgentRunner │
|
|
90
|
+
│ types │ useAgent │ callTool │ │
|
|
91
|
+
├──────────┼──────────┼──────────┼──────────────────┤
|
|
92
|
+
│ Registry │ Subscrip │ A2A │ Reputation │
|
|
93
|
+
│ register │ subscribe│ protocol │ giveFeedback │
|
|
94
|
+
│ query │ verify │ │ │
|
|
95
|
+
└──────────┴──────────┴──────────┴──────────────────┘
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## API Reference
|
|
99
|
+
|
|
100
|
+
### `@agentx/sdk` (Core)
|
|
101
|
+
|
|
102
|
+
| Export | Description |
|
|
103
|
+
|--------|-------------|
|
|
104
|
+
| `AgentRunner` | Main entry: decrypts + loads Agent context |
|
|
105
|
+
| `packForPublish` / `encryptPayload` / `decryptPayload` | AES-256-GCM encrypt/decrypt |
|
|
106
|
+
| `generateAesKey` / `generateKeyPair` | Key generation |
|
|
107
|
+
| `eciesEncrypt` / `eciesDecrypt` / `unpackAgent` | ECIES key wrapping |
|
|
108
|
+
| `MCPConnector` | MCP tool discovery + execution |
|
|
109
|
+
| `IPFSFetcher` | Fetch encrypted payloads from IPFS |
|
|
110
|
+
| `AgentRegistry` | Register and query agents on-chain |
|
|
111
|
+
| `SubscriptionManager` | Subscribe (ETH/ERC20), verify, cancel, trial refund, releaseFunds |
|
|
112
|
+
| `AgentX402` | Auto-subscription gate + X402 payment bridge |
|
|
113
|
+
| `A2AProtocol` | Agent-to-Agent task protocol |
|
|
114
|
+
|
|
115
|
+
### Agent Composition (A2A Skills)
|
|
116
|
+
|
|
117
|
+
An Agent's Skill can delegate to **another Agent**. Set `execution.type = "a2a"`:
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
{
|
|
121
|
+
name: "solidity_audit",
|
|
122
|
+
description: "Delegate to Auditing Agent #42",
|
|
123
|
+
execution: {
|
|
124
|
+
type: "a2a",
|
|
125
|
+
targetAgentId: 42, // On-chain Agent ID
|
|
126
|
+
skillFilter: ["slither"], // Optional: restrict exposed skills
|
|
127
|
+
},
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
When executed, the SDK loads Agent #42's prompt + skills, decrypts them,
|
|
132
|
+
and returns the full sub-Agent context to the calling LLM.
|
|
133
|
+
| `ReputationRegistry` | Give feedback + query reputation |
|
|
134
|
+
|
|
135
|
+
### `@agentx/sdk/react`
|
|
136
|
+
|
|
137
|
+
| Export | Description |
|
|
138
|
+
|--------|-------------|
|
|
139
|
+
| `useAgentRunner({ agentId })` | React hook: load + decrypt Agent |
|
|
140
|
+
|
|
141
|
+
### `@agentx/sdk/core`
|
|
142
|
+
|
|
143
|
+
| Export | Description |
|
|
144
|
+
|--------|-------------|
|
|
145
|
+
| All types: `AgentPayload`, `SkillDef`, `McpConnection`, `PricingInfo`, `AgentRunContext`, etc. | |
|
|
146
|
+
| All crypto: `encryptPayload`, `decryptPayload`, `generateAesKey`, `eciesEncrypt`, `eciesDecrypt` | |
|
|
147
|
+
|
|
148
|
+
## Encryption Pipeline
|
|
149
|
+
|
|
150
|
+
```
|
|
151
|
+
Publisher creates Agent
|
|
152
|
+
│
|
|
153
|
+
├─ AgentPrivatePayload { prompt, skills, mcp }
|
|
154
|
+
├─ encryptPayload() → AES-256-GCM ciphertext
|
|
155
|
+
├─ Upload ciphertext to IPFS → get CID
|
|
156
|
+
├─ aesKey → stored as on-chain NFT metadata (aes_key_hex)
|
|
157
|
+
└─ Mint Agent NFT via IdentityRegistry
|
|
158
|
+
|
|
159
|
+
Subscriber uses Agent
|
|
160
|
+
│
|
|
161
|
+
├─ Verify on-chain subscription (SubscriptionManager)
|
|
162
|
+
├─ Fetch encrypted payload from IPFS (CID from NFT metadata)
|
|
163
|
+
├─ Read aes_key_hex from on-chain NFT attributes
|
|
164
|
+
├─ decryptPayload() → { prompt, skills, mcp }
|
|
165
|
+
└─ skills[n].execute() → Open (local) or MCP (remote with signed auth)
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## Closed Skill Execution (MCP Remote)
|
|
169
|
+
|
|
170
|
+
Skills with `execution.type === 'mcp'` execute on the publisher's server:
|
|
171
|
+
|
|
172
|
+
```
|
|
173
|
+
Client Publisher MCP Server
|
|
174
|
+
│ │
|
|
175
|
+
├─ ECDSA sign(toolName + timestamp) │
|
|
176
|
+
├─ POST { X-Subscriber-Address, │
|
|
177
|
+
│ X-Signature, │
|
|
178
|
+
│ X-Timestamp } │
|
|
179
|
+
│ + JSON-RPC tools/call │
|
|
180
|
+
│ ├─ Verify signature
|
|
181
|
+
│ ├─ Check on-chain subscription
|
|
182
|
+
│ ├─ Execute skill
|
|
183
|
+
│◄── Return result ──────────────────┤
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
## On-Chain Contracts (Sepolia)
|
|
187
|
+
|
|
188
|
+
| Contract | Address |
|
|
189
|
+
|----------|---------|
|
|
190
|
+
| IdentityRegistry | `0xe94ad380d3F8d08a7590eda0C84f354a93F96e5F` |
|
|
191
|
+
| SubscriptionManager | `0x62AB377BEA26Fa1818dfB0c71ef5b272dc9376f5` |
|
|
192
|
+
|
|
193
|
+
## License
|
|
194
|
+
|
|
195
|
+
MIT
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { PublicClient, WalletClient, Address, Hash } from 'viem';
|
|
2
|
+
import type { A2AAgentCard, A2ATask } from '../core/types';
|
|
3
|
+
export interface A2AConfig {
|
|
4
|
+
contractAddress: Address;
|
|
5
|
+
publicClient: PublicClient;
|
|
6
|
+
walletClient: WalletClient;
|
|
7
|
+
}
|
|
8
|
+
export declare class A2AProtocol {
|
|
9
|
+
private address;
|
|
10
|
+
private publicClient;
|
|
11
|
+
private walletClient;
|
|
12
|
+
constructor(config: A2AConfig);
|
|
13
|
+
private get account();
|
|
14
|
+
createAgentCard(agentId: number, card: {
|
|
15
|
+
name: string;
|
|
16
|
+
description: string;
|
|
17
|
+
version: string;
|
|
18
|
+
capabilities: string[];
|
|
19
|
+
supportedTasks: string[];
|
|
20
|
+
commProtocol?: string;
|
|
21
|
+
authMethod?: string;
|
|
22
|
+
cardURI?: string;
|
|
23
|
+
}): Promise<{
|
|
24
|
+
cardId: number;
|
|
25
|
+
txHash: Hash;
|
|
26
|
+
}>;
|
|
27
|
+
getAgentCard(agentId: number): Promise<A2AAgentCard | null>;
|
|
28
|
+
createTask(agentId: number, taskType: string, input: Record<string, unknown>): Promise<{
|
|
29
|
+
taskId: number;
|
|
30
|
+
txHash: Hash;
|
|
31
|
+
}>;
|
|
32
|
+
completeTask(taskId: number, output: unknown): Promise<Hash>;
|
|
33
|
+
getTask(taskId: number): Promise<A2ATask | null>;
|
|
34
|
+
getUserTasks(user: Address): Promise<number[]>;
|
|
35
|
+
private _parseUintFromLog;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=a2a.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"a2a.d.ts","sourceRoot":"","sources":["../../src/a2a/a2a.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AACrE,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAiB,MAAM,eAAe,CAAA;AAsHzE,MAAM,WAAW,SAAS;IACxB,eAAe,EAAE,OAAO,CAAA;IACxB,YAAY,EAAE,YAAY,CAAA;IAC1B,YAAY,EAAE,YAAY,CAAA;CAC3B;AAID,qBAAa,WAAW;IACtB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,YAAY,CAAc;IAClC,OAAO,CAAC,YAAY,CAAc;gBAEtB,MAAM,EAAE,SAAS;IAM7B,OAAO,KAAK,OAAO,GAKlB;IAIK,eAAe,CACnB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,EAAE,CAAC;QAAC,cAAc,EAAE,MAAM,EAAE,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,GAC3K,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,IAAI,CAAA;KAAE,CAAC;IAoBtC,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;IAqB3D,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,IAAI,CAAA;KAAE,CAAC;IAgBxH,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAa5D,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;IAsBhD,YAAY,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAYpD,OAAO,CAAC,iBAAiB;CAW1B"}
|
package/dist/a2a/a2a.js
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// @agentx/sdk — A2A Protocol
|
|
3
|
+
// ---------------------------------------------------------------------------
|
|
4
|
+
// Wraps A2AProtocolRegistry: Agent Cards, Skills, and Tasks.
|
|
5
|
+
// viem PublicClient / WalletClient based.
|
|
6
|
+
// ---------------------------------------------------------------------------
|
|
7
|
+
// ── ABI Fragments ──────────────────────────────────────────────────────────
|
|
8
|
+
const A2A_ABI = {
|
|
9
|
+
createAgentCard: {
|
|
10
|
+
inputs: [
|
|
11
|
+
{ name: 'agentId', type: 'uint256' },
|
|
12
|
+
{ name: 'name', type: 'string' },
|
|
13
|
+
{ name: 'description', type: 'string' },
|
|
14
|
+
{ name: 'version', type: 'string' },
|
|
15
|
+
{ name: 'capabilities', type: 'string[]' },
|
|
16
|
+
{ name: 'supportedTasks', type: 'string[]' },
|
|
17
|
+
{ name: 'communicationProtocol', type: 'string' },
|
|
18
|
+
{ name: 'authenticationMethod', type: 'string' },
|
|
19
|
+
{ name: 'cardURI', type: 'string' },
|
|
20
|
+
],
|
|
21
|
+
name: 'createAgentCard',
|
|
22
|
+
outputs: [{ name: 'cardId', type: 'uint256' }],
|
|
23
|
+
stateMutability: 'nonpayable',
|
|
24
|
+
type: 'function',
|
|
25
|
+
},
|
|
26
|
+
getAgentCard: {
|
|
27
|
+
inputs: [{ name: 'agentId', type: 'uint256' }],
|
|
28
|
+
name: 'getAgentCard',
|
|
29
|
+
outputs: [
|
|
30
|
+
{ name: 'cardId', type: 'uint256' },
|
|
31
|
+
{ name: 'agentId', type: 'uint256' },
|
|
32
|
+
{ name: 'name', type: 'string' },
|
|
33
|
+
{ name: 'description', type: 'string' },
|
|
34
|
+
{ name: 'version', type: 'string' },
|
|
35
|
+
{ name: 'capabilities', type: 'string[]' },
|
|
36
|
+
{ name: 'supportedTasks', type: 'string[]' },
|
|
37
|
+
{ name: 'communicationProtocol', type: 'string' },
|
|
38
|
+
{ name: 'authenticationMethod', type: 'string' },
|
|
39
|
+
{ name: 'cardURI', type: 'string' },
|
|
40
|
+
{ name: 'isActive', type: 'bool' },
|
|
41
|
+
],
|
|
42
|
+
stateMutability: 'view',
|
|
43
|
+
type: 'function',
|
|
44
|
+
},
|
|
45
|
+
registerSkill: {
|
|
46
|
+
inputs: [
|
|
47
|
+
{ name: 'name', type: 'string' },
|
|
48
|
+
{ name: 'description', type: 'string' },
|
|
49
|
+
{ name: 'inputSchema', type: 'string' },
|
|
50
|
+
{ name: 'outputSchema', type: 'string' },
|
|
51
|
+
{ name: 'requiredCapabilities', type: 'string[]' },
|
|
52
|
+
{ name: 'complexity', type: 'uint256' },
|
|
53
|
+
],
|
|
54
|
+
name: 'registerSkill',
|
|
55
|
+
outputs: [{ name: 'skillId', type: 'uint256' }],
|
|
56
|
+
stateMutability: 'nonpayable',
|
|
57
|
+
type: 'function',
|
|
58
|
+
},
|
|
59
|
+
addAgentSkill: {
|
|
60
|
+
inputs: [
|
|
61
|
+
{ name: 'agentId', type: 'uint256' },
|
|
62
|
+
{ name: 'skillId', type: 'uint256' },
|
|
63
|
+
{ name: 'skillEndpoint', type: 'string' },
|
|
64
|
+
{ name: 'version', type: 'string' },
|
|
65
|
+
{ name: 'price', type: 'uint256' },
|
|
66
|
+
{ name: 'priceToken', type: 'address' },
|
|
67
|
+
],
|
|
68
|
+
name: 'addAgentSkill',
|
|
69
|
+
outputs: [],
|
|
70
|
+
stateMutability: 'nonpayable',
|
|
71
|
+
type: 'function',
|
|
72
|
+
},
|
|
73
|
+
createTask: {
|
|
74
|
+
inputs: [
|
|
75
|
+
{ name: 'agentId', type: 'uint256' },
|
|
76
|
+
{ name: 'taskType', type: 'string' },
|
|
77
|
+
{ name: 'inputData', type: 'string' },
|
|
78
|
+
],
|
|
79
|
+
name: 'createTask',
|
|
80
|
+
outputs: [{ name: 'taskId', type: 'uint256' }],
|
|
81
|
+
stateMutability: 'nonpayable',
|
|
82
|
+
type: 'function',
|
|
83
|
+
},
|
|
84
|
+
completeTask: {
|
|
85
|
+
inputs: [
|
|
86
|
+
{ name: 'taskId', type: 'uint256' },
|
|
87
|
+
{ name: 'outputData', type: 'string' },
|
|
88
|
+
],
|
|
89
|
+
name: 'completeTask',
|
|
90
|
+
outputs: [],
|
|
91
|
+
stateMutability: 'nonpayable',
|
|
92
|
+
type: 'function',
|
|
93
|
+
},
|
|
94
|
+
getTask: {
|
|
95
|
+
inputs: [{ name: 'taskId', type: 'uint256' }],
|
|
96
|
+
name: 'getTask',
|
|
97
|
+
outputs: [
|
|
98
|
+
{ name: 'taskId', type: 'uint256' },
|
|
99
|
+
{ name: 'agentId', type: 'uint256' },
|
|
100
|
+
{ name: 'taskType', type: 'string' },
|
|
101
|
+
{ name: 'inputData', type: 'string' },
|
|
102
|
+
{ name: 'outputData', type: 'string' },
|
|
103
|
+
{ name: 'status', type: 'uint256' },
|
|
104
|
+
{ name: 'clientAddress', type: 'address' },
|
|
105
|
+
{ name: 'createdAt', type: 'uint256' },
|
|
106
|
+
{ name: 'completedAt', type: 'uint256' },
|
|
107
|
+
],
|
|
108
|
+
stateMutability: 'view',
|
|
109
|
+
type: 'function',
|
|
110
|
+
},
|
|
111
|
+
getUserTasks: {
|
|
112
|
+
inputs: [{ name: 'user', type: 'address' }],
|
|
113
|
+
name: 'getUserTasks',
|
|
114
|
+
outputs: [{ name: '', type: 'uint256[]' }],
|
|
115
|
+
stateMutability: 'view',
|
|
116
|
+
type: 'function',
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
// ── A2A Protocol ───────────────────────────────────────────────────────────
|
|
120
|
+
export class A2AProtocol {
|
|
121
|
+
address;
|
|
122
|
+
publicClient;
|
|
123
|
+
walletClient;
|
|
124
|
+
constructor(config) {
|
|
125
|
+
this.address = config.contractAddress;
|
|
126
|
+
this.publicClient = config.publicClient;
|
|
127
|
+
this.walletClient = config.walletClient;
|
|
128
|
+
}
|
|
129
|
+
get account() {
|
|
130
|
+
return this.walletClient.getAddresses().then(a => {
|
|
131
|
+
if (!a[0])
|
|
132
|
+
throw new Error('Wallet not connected');
|
|
133
|
+
return a[0];
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
// ── Agent Card ──────────────────────────────────────────────────────────
|
|
137
|
+
async createAgentCard(agentId, card) {
|
|
138
|
+
const acct = await this.account;
|
|
139
|
+
const { request } = await this.publicClient.simulateContract({
|
|
140
|
+
account: acct,
|
|
141
|
+
address: this.address,
|
|
142
|
+
abi: [A2A_ABI.createAgentCard],
|
|
143
|
+
functionName: 'createAgentCard',
|
|
144
|
+
args: [
|
|
145
|
+
BigInt(agentId), card.name, card.description, card.version,
|
|
146
|
+
card.capabilities, card.supportedTasks,
|
|
147
|
+
card.commProtocol ?? 'a2a', card.authMethod ?? 'ecdsa',
|
|
148
|
+
card.cardURI ?? '',
|
|
149
|
+
],
|
|
150
|
+
});
|
|
151
|
+
const hash = await this.walletClient.writeContract(request);
|
|
152
|
+
const receipt = await this.publicClient.waitForTransactionReceipt({ hash });
|
|
153
|
+
const cardId = this._parseUintFromLog(receipt, 'AgentCardCreated');
|
|
154
|
+
return { cardId, txHash: hash };
|
|
155
|
+
}
|
|
156
|
+
async getAgentCard(agentId) {
|
|
157
|
+
const r = await this.publicClient.readContract({
|
|
158
|
+
address: this.address,
|
|
159
|
+
abi: [A2A_ABI.getAgentCard],
|
|
160
|
+
functionName: 'getAgentCard',
|
|
161
|
+
args: [BigInt(agentId)],
|
|
162
|
+
});
|
|
163
|
+
const [, aId, name, , , capabilities, supportedTasks, , , , isActive] = r;
|
|
164
|
+
if (!isActive)
|
|
165
|
+
return null;
|
|
166
|
+
return {
|
|
167
|
+
agentId: Number(aId),
|
|
168
|
+
name: name,
|
|
169
|
+
capabilities: capabilities,
|
|
170
|
+
supportedTasks: supportedTasks,
|
|
171
|
+
endpoint: '',
|
|
172
|
+
publicKey: '',
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
// ── Task ────────────────────────────────────────────────────────────────
|
|
176
|
+
async createTask(agentId, taskType, input) {
|
|
177
|
+
const acct = await this.account;
|
|
178
|
+
const inputStr = JSON.stringify(input);
|
|
179
|
+
const { request } = await this.publicClient.simulateContract({
|
|
180
|
+
account: acct,
|
|
181
|
+
address: this.address,
|
|
182
|
+
abi: [A2A_ABI.createTask],
|
|
183
|
+
functionName: 'createTask',
|
|
184
|
+
args: [BigInt(agentId), taskType, inputStr],
|
|
185
|
+
});
|
|
186
|
+
const hash = await this.walletClient.writeContract(request);
|
|
187
|
+
const receipt = await this.publicClient.waitForTransactionReceipt({ hash });
|
|
188
|
+
const taskId = this._parseUintFromLog(receipt, 'TaskCreated');
|
|
189
|
+
return { taskId, txHash: hash };
|
|
190
|
+
}
|
|
191
|
+
async completeTask(taskId, output) {
|
|
192
|
+
const acct = await this.account;
|
|
193
|
+
const outputStr = typeof output === 'string' ? output : JSON.stringify(output);
|
|
194
|
+
const { request } = await this.publicClient.simulateContract({
|
|
195
|
+
account: acct,
|
|
196
|
+
address: this.address,
|
|
197
|
+
abi: [A2A_ABI.completeTask],
|
|
198
|
+
functionName: 'completeTask',
|
|
199
|
+
args: [BigInt(taskId), outputStr],
|
|
200
|
+
});
|
|
201
|
+
return this.walletClient.writeContract(request);
|
|
202
|
+
}
|
|
203
|
+
async getTask(taskId) {
|
|
204
|
+
const r = await this.publicClient.readContract({
|
|
205
|
+
address: this.address,
|
|
206
|
+
abi: [A2A_ABI.getTask],
|
|
207
|
+
functionName: 'getTask',
|
|
208
|
+
args: [BigInt(taskId)],
|
|
209
|
+
});
|
|
210
|
+
const [, aId, taskType, inputData, outputData, status, client, createdAt, completedAt] = r;
|
|
211
|
+
const statusMap = ['created', 'accepted', 'in_progress', 'completed', 'failed'];
|
|
212
|
+
return {
|
|
213
|
+
taskId: taskId,
|
|
214
|
+
creator: client,
|
|
215
|
+
targetAgentId: Number(aId),
|
|
216
|
+
taskType: taskType,
|
|
217
|
+
input: inputData,
|
|
218
|
+
status: statusMap[Number(status)] ?? 'created',
|
|
219
|
+
result: outputData,
|
|
220
|
+
createdAt: Number(createdAt),
|
|
221
|
+
completedAt: completedAt > 0n ? Number(completedAt) : undefined,
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
async getUserTasks(user) {
|
|
225
|
+
const r = await this.publicClient.readContract({
|
|
226
|
+
address: this.address,
|
|
227
|
+
abi: [A2A_ABI.getUserTasks],
|
|
228
|
+
functionName: 'getUserTasks',
|
|
229
|
+
args: [user],
|
|
230
|
+
});
|
|
231
|
+
return r.map(Number);
|
|
232
|
+
}
|
|
233
|
+
// ── Helpers ─────────────────────────────────────────────────────────────
|
|
234
|
+
_parseUintFromLog(receipt, _eventName) {
|
|
235
|
+
for (const log of receipt.logs) {
|
|
236
|
+
if (log.topics.length >= 2) {
|
|
237
|
+
try {
|
|
238
|
+
return Number(BigInt(log.topics[1]));
|
|
239
|
+
}
|
|
240
|
+
catch { /* */ }
|
|
241
|
+
}
|
|
242
|
+
if (log.data && log.data !== '0x') {
|
|
243
|
+
try {
|
|
244
|
+
return Number(BigInt(log.data));
|
|
245
|
+
}
|
|
246
|
+
catch { /* */ }
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return 0;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
//# sourceMappingURL=a2a.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"a2a.js","sourceRoot":"","sources":["../../src/a2a/a2a.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,6BAA6B;AAC7B,8EAA8E;AAC9E,6DAA6D;AAC7D,0CAA0C;AAC1C,8EAA8E;AAM9E,8EAA8E;AAE9E,MAAM,OAAO,GAAG;IACd,eAAe,EAAE;QACf,MAAM,EAAE;YACN,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE;YACpC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE;YAChC,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,QAAQ,EAAE;YACvC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE;YACnC,EAAE,IAAI,EAAE,cAAc,EAAE,IAAI,EAAE,UAAU,EAAE;YAC1C,EAAE,IAAI,EAAE,gBAAgB,EAAE,IAAI,EAAE,UAAU,EAAE;YAC5C,EAAE,IAAI,EAAE,uBAAuB,EAAE,IAAI,EAAE,QAAQ,EAAE;YACjD,EAAE,IAAI,EAAE,sBAAsB,EAAE,IAAI,EAAE,QAAQ,EAAE;YAChD,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE;SAC3B;QACV,IAAI,EAAE,iBAA0B;QAChC,OAAO,EAAE,CAAC,EAAE,I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C3B,YAAY,EAAE,cAAc;YAC5B,IAAI,EAAE,CAAC,IAAI,CAAC;SACb,CAAC,CAAA;QACF,OAAQ,CAAc,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;IACpC,CAAC;IAED,2EAA2E;IAEnE,iBAAiB,CAAC,OAAwD,EAAE,UAAkB;QACpG,KAAK,MAAM,GAAG,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;YAC/B,IAAI,GAAG,CAAC,MAAM,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC;gBAC3B,IAAI,CAAC;oBAAC,OAAO,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAE,CAAC,CAAC,CAAA;gBAAC,CAAC;gBAAC,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC;YAC/D,CAAC;YACD,IAAI,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;gBAClC,IAAI,CAAC;oBAAC,OAAO,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAA;gBAAC,CAAC;gBAAC,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC;YACzD,CAAC;QACH,CAAC;QACD,OAAO,CAAC,CAAA;IACV,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/a2a/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAA;AACnC,YAAY,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AACtC,eAAO,MAAM,WAAW,UAAU,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/a2a/index.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAC3B,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAA;AAEnC,MAAM,CAAC,MAAM,WAAW,GAAG,OAAO,CAAA"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { IPFSFetcher } from '../registry/ipfs-fetcher';
|
|
2
|
+
import type { AgentPayload, PackResult } from '../core/types';
|
|
3
|
+
/** Minimal on-chain reader interface — implement with viem. */
|
|
4
|
+
export interface OnChainReader {
|
|
5
|
+
/** Read tokenURI from IdentityRegistry by tokenId. */
|
|
6
|
+
getTokenURI(agentId: number): Promise<string>;
|
|
7
|
+
/** Get agent metadata attributes (returned as key-value pairs). */
|
|
8
|
+
getAttributes(agentId: number): Promise<Record<string, string>>;
|
|
9
|
+
/** Check if `address` has an active subscription for `agentId`. */
|
|
10
|
+
hasActiveSubscription(address: string, agentId: number): Promise<boolean>;
|
|
11
|
+
}
|
|
12
|
+
/** Minimal wallet signer interface — implement with wagmi/viem. */
|
|
13
|
+
export interface WalletSigner {
|
|
14
|
+
/** Sign a message (for authentication to MCP servers). */
|
|
15
|
+
signMessage(message: string): Promise<string>;
|
|
16
|
+
/** Get the current wallet address. */
|
|
17
|
+
getAddress(): Promise<string>;
|
|
18
|
+
/** Get the wallet's ECDSA private key (required for ECIES decryption). */
|
|
19
|
+
getPrivateKey?(): Promise<string>;
|
|
20
|
+
}
|
|
21
|
+
export interface AgentRunnerConfig {
|
|
22
|
+
/** On-chain data reader (injected from viem/wagmi). */
|
|
23
|
+
reader: OnChainReader;
|
|
24
|
+
/** Wallet signer (injected from wagmi). */
|
|
25
|
+
wallet: WalletSigner;
|
|
26
|
+
/** IPFS fetcher instance (creates default if omitted). */
|
|
27
|
+
ipfsFetcher?: IPFSFetcher;
|
|
28
|
+
/** IPFS gateway list (overrides IPFSFetcher defaults). */
|
|
29
|
+
ipfsGateways?: string[];
|
|
30
|
+
}
|
|
31
|
+
export interface AgentRunContext {
|
|
32
|
+
/** Agent NFT token ID */
|
|
33
|
+
agentId: number;
|
|
34
|
+
/** System prompt — inject into LLM conversation */
|
|
35
|
+
prompt: string;
|
|
36
|
+
/** All skills with execution metadata */
|
|
37
|
+
skills: RunnableSkill[];
|
|
38
|
+
/** MCP connection info */
|
|
39
|
+
mcp: {
|
|
40
|
+
type: string;
|
|
41
|
+
url?: string;
|
|
42
|
+
toolFilter?: string[];
|
|
43
|
+
};
|
|
44
|
+
/** Subscription expiry timestamp (0 = unknown) */
|
|
45
|
+
subscriptionExpiry: number;
|
|
46
|
+
}
|
|
47
|
+
export interface RunnableSkill {
|
|
48
|
+
name: string;
|
|
49
|
+
description: string;
|
|
50
|
+
inputSchema: Record<string, unknown>;
|
|
51
|
+
outputSchema?: Record<string, unknown>;
|
|
52
|
+
/** Execution mode */
|
|
53
|
+
mode: 'open' | 'mcp' | 'a2a';
|
|
54
|
+
/** If mode='a2a', the on-chain Agent ID being delegated to */
|
|
55
|
+
a2aTargetAgentId?: number;
|
|
56
|
+
/**
|
|
57
|
+
* Execute this skill with the given input.
|
|
58
|
+
* - Open: runs locally (caller provides implementation)
|
|
59
|
+
* - MCP: POSTs to the publisher's MCP server
|
|
60
|
+
* - A2A: loads target Agent context (prompt+skills) via AgentRunner
|
|
61
|
+
*/
|
|
62
|
+
execute(input: Record<string, unknown>): Promise<unknown>;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Standard return type for A2A skill execution.
|
|
66
|
+
* The calling LLM receives the sub-Agent's prompt and skills
|
|
67
|
+
* and can inject them into the conversation.
|
|
68
|
+
*/
|
|
69
|
+
export interface A2ASkillResult {
|
|
70
|
+
/** On-chain Agent ID that was delegated to */
|
|
71
|
+
agentId: number;
|
|
72
|
+
/** Sub-Agent's decrypted system prompt */
|
|
73
|
+
prompt: string;
|
|
74
|
+
/** Sub-Agent's skills (name + description + schema only, no execute) */
|
|
75
|
+
skills: {
|
|
76
|
+
name: string;
|
|
77
|
+
description: string;
|
|
78
|
+
inputSchema: Record<string, unknown>;
|
|
79
|
+
}[];
|
|
80
|
+
/** The original input passed by the caller */
|
|
81
|
+
callerInput: Record<string, unknown>;
|
|
82
|
+
}
|
|
83
|
+
export declare class AgentRunner {
|
|
84
|
+
private reader;
|
|
85
|
+
private wallet;
|
|
86
|
+
private ipfs;
|
|
87
|
+
constructor(config: AgentRunnerConfig);
|
|
88
|
+
/**
|
|
89
|
+
* Load and decrypt an Agent, returning a run context ready to inject
|
|
90
|
+
* into any LLM conversation.
|
|
91
|
+
*
|
|
92
|
+
* Steps:
|
|
93
|
+
* 1. Verify on-chain subscription (frontend check)
|
|
94
|
+
* 2. Fetch metadata → get encryptedPayloadCid + eciesEncryptedKey
|
|
95
|
+
* 3. IPFS fetch encrypted payload
|
|
96
|
+
* 4. ECIES decrypt AES key (using wallet private key)
|
|
97
|
+
* 5. AES-256-GCM decrypt payload → { prompt, skills, mcp }
|
|
98
|
+
* 6. Build RunnableSkill wrappers (Open: local stub, Closed: MCP remote)
|
|
99
|
+
*/
|
|
100
|
+
useAgent(agentId: number): Promise<AgentRunContext>;
|
|
101
|
+
/**
|
|
102
|
+
* Pack an AgentPayload for publishing (encryption only, no IPFS upload).
|
|
103
|
+
* Caller is responsible for IPFS upload and on-chain registration.
|
|
104
|
+
*/
|
|
105
|
+
packForPublish(payload: AgentPayload, publicKey: string): PackResult;
|
|
106
|
+
/** Wrap a SkillDef into a RunnableSkill with execute(). */
|
|
107
|
+
private _wrapSkill;
|
|
108
|
+
/** Call a tool on the publisher's MCP server (Closed skill). */
|
|
109
|
+
private _executeMCPTool;
|
|
110
|
+
/**
|
|
111
|
+
* Execute an A2A skill — delegate to another AgentX Agent.
|
|
112
|
+
*
|
|
113
|
+
* Standard Interface:
|
|
114
|
+
* Input: { task, ...taskSpecificParams }
|
|
115
|
+
* Output: { agentId, prompt, skills[] }
|
|
116
|
+
*
|
|
117
|
+
* The caller (LLM) receives the sub-Agent's prompt + skill list.
|
|
118
|
+
* The LLM then decides how to use the sub-Agent — typically by
|
|
119
|
+
* injecting the sub-Agent's system prompt and calling its skills.
|
|
120
|
+
*/
|
|
121
|
+
private _executeA2ASkill;
|
|
122
|
+
private _getPrivateKey;
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=agent-runner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-runner.d.ts","sourceRoot":"","sources":["../../src/agent/agent-runner.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AACtD,OAAO,KAAK,EACV,YAAY,EAEZ,UAAU,EACX,MAAM,eAAe,CAAA;AAKtB,+DAA+D;AAC/D,MAAM,WAAW,aAAa;IAC5B,sDAAsD;IACtD,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;IAC7C,mEAAmE;IACnE,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;IAC/D,mEAAmE;IACnE,qBAAqB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;CAC1E;AAED,mEAAmE;AACnE,MAAM,WAAW,YAAY;IAC3B,0DAA0D;IAC1D,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;IAC7C,sCAAsC;IACtC,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC,CAAA;IAC7B,0EAA0E;IAC1E,aAAa,CAAC,IAAI,OAAO,CAAC,MAAM,CAAC,CAAA;CAClC;AAID,MAAM,WAAW,iBAAiB;IAChC,uDAAuD;IACvD,MAAM,EAAE,aAAa,CAAA;IACrB,2CAA2C;IAC3C,MAAM,EAAE,YAAY,CAAA;IACpB,0DAA0D;IAC1D,WAAW,CAAC,EAAE,WAAW,CAAA;IACzB,0DAA0D;IAC1D,YAAY,CAAC,EAAE,MAAM,EAAE,CAAA;CACxB;AAID,MAAM,WAAW,eAAe;IAC9B,yBAAyB;IACzB,OAAO,EAAE,MAAM,CAAA;IACf,mDAAmD;IACnD,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