@xpr-agents/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/README.md ADDED
@@ -0,0 +1,165 @@
1
+ # @xpr-agents/sdk
2
+
3
+ TypeScript SDK for the XPR Network Trustless Agent Registry.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @xpr-agents/sdk @proton/js
9
+ ```
10
+
11
+ For browser/frontend usage with wallet integration:
12
+ ```bash
13
+ npm install @xpr-agents/sdk @proton/js @proton/web-sdk
14
+ ```
15
+
16
+ ## Quick Start
17
+
18
+ ### Read-Only Operations (No Wallet)
19
+
20
+ ```typescript
21
+ import { JsonRpc } from '@proton/js';
22
+ import { AgentRegistry, FeedbackRegistry, ValidationRegistry, EscrowRegistry } from '@xpr-agents/sdk';
23
+
24
+ const rpc = new JsonRpc('https://proton.eosusa.io');
25
+
26
+ // Initialize registries
27
+ const agents = new AgentRegistry(rpc);
28
+ const feedback = new FeedbackRegistry(rpc);
29
+ const validation = new ValidationRegistry(rpc);
30
+ const escrow = new EscrowRegistry(rpc);
31
+
32
+ // Query agents
33
+ const agent = await agents.getAgent('myagent');
34
+ const allAgents = await agents.listAgents({ active_only: true });
35
+
36
+ // Get trust score
37
+ const trustScore = await agents.getTrustScore('myagent');
38
+ console.log(`Trust score: ${trustScore.total}/100`);
39
+
40
+ // Query feedback
41
+ const agentFeedback = await feedback.listFeedbackForAgent('myagent');
42
+
43
+ // Query jobs
44
+ const job = await escrow.getJob(1);
45
+ const clientJobs = await escrow.listJobsByClient('clientacc');
46
+ ```
47
+
48
+ ### Write Operations (With Wallet)
49
+
50
+ ```typescript
51
+ import ProtonWebSDK from '@proton/web-sdk';
52
+ import { AgentRegistry, FeedbackRegistry } from '@xpr-agents/sdk';
53
+
54
+ // Connect wallet
55
+ const { link, session } = await ProtonWebSDK({
56
+ linkOptions: {
57
+ chainId: '384da888112027f0321850a169f737c33e53b388aad48b5adace4bab97f437e0',
58
+ endpoints: ['https://proton.eosusa.io'],
59
+ },
60
+ selectorOptions: { appName: 'My App' },
61
+ });
62
+
63
+ // Initialize with session for write operations
64
+ const agents = new AgentRegistry(link.rpc, session);
65
+ const feedback = new FeedbackRegistry(link.rpc, session);
66
+
67
+ // Register as an agent
68
+ await agents.register({
69
+ name: 'My AI Agent',
70
+ description: 'An AI assistant',
71
+ endpoint: 'https://api.myagent.com',
72
+ protocol: 'https',
73
+ capabilities: ['compute', 'ai'],
74
+ });
75
+
76
+ // Submit feedback
77
+ await feedback.submit({
78
+ agent: 'otheragent',
79
+ score: 5,
80
+ tags: ['helpful', 'fast'],
81
+ job_hash: 'abc123',
82
+ });
83
+ ```
84
+
85
+ ## API Reference
86
+
87
+ ### AgentRegistry
88
+
89
+ | Method | Description |
90
+ |--------|-------------|
91
+ | `getAgent(account)` | Get agent by account name |
92
+ | `listAgents(options?)` | List agents with optional filters |
93
+ | `getTrustScore(account)` | Calculate trust score (0-100) |
94
+ | `register(data)` | Register as an agent |
95
+ | `update(data)` | Update agent metadata |
96
+ | `setStatus(active)` | Toggle active status |
97
+
98
+ ### FeedbackRegistry
99
+
100
+ | Method | Description |
101
+ |--------|-------------|
102
+ | `getFeedback(id)` | Get feedback by ID |
103
+ | `listFeedbackForAgent(agent)` | Get all feedback for an agent |
104
+ | `getAgentScore(agent)` | Get aggregated score |
105
+ | `submit(data)` | Submit feedback |
106
+ | `dispute(id, reason)` | Dispute feedback |
107
+
108
+ ### ValidationRegistry
109
+
110
+ | Method | Description |
111
+ |--------|-------------|
112
+ | `getValidator(account)` | Get validator info |
113
+ | `listValidators(options?)` | List validators |
114
+ | `getValidation(id)` | Get validation by ID |
115
+ | `registerValidator(method, specs)` | Register as validator |
116
+ | `validate(data)` | Submit validation |
117
+ | `challenge(validationId, reason)` | Challenge a validation |
118
+ | `stakeChallengeDeposit(id, amount)` | Fund a challenge |
119
+ | `stake(amount)` | Stake XPR as validator |
120
+ | `unstake(amount)` | Request unstake (time-delayed) |
121
+ | `withdraw(unstakeId)` | Withdraw after delay |
122
+ | `setValidatorStatus(active)` | Toggle validator status |
123
+ | `cancelChallenge(id)` | Cancel unfunded challenge |
124
+
125
+ ### EscrowRegistry
126
+
127
+ | Method | Description |
128
+ |--------|-------------|
129
+ | `getJob(id)` | Get job by ID |
130
+ | `listJobsByClient(client)` | List jobs for a client |
131
+ | `listJobsByAgent(agent)` | List jobs for an agent |
132
+ | `createJob(data)` | Create a new job |
133
+ | `fundJob(jobId, amount)` | Fund a job |
134
+ | `acceptJob(jobId)` | Accept a job (agent) |
135
+ | `deliver(jobId, uri)` | Submit deliverables |
136
+ | `approve(jobId)` | Approve and release payment |
137
+ | `dispute(jobId, reason)` | Raise a dispute |
138
+
139
+ ## Networks
140
+
141
+ | Network | Chain ID | Endpoints |
142
+ |---------|----------|-----------|
143
+ | Mainnet | `384da888...` | `https://proton.eosusa.io` |
144
+ | Testnet | `71ee83bc...` | `https://testnet.protonchain.com` |
145
+
146
+ ## Types
147
+
148
+ All TypeScript types are exported:
149
+
150
+ ```typescript
151
+ import type {
152
+ Agent,
153
+ Feedback,
154
+ Validator,
155
+ Validation,
156
+ Challenge,
157
+ Job,
158
+ Milestone,
159
+ TrustScore,
160
+ } from '@xpr-agents/sdk';
161
+ ```
162
+
163
+ ## License
164
+
165
+ MIT
@@ -0,0 +1,182 @@
1
+ import { Agent, Plugin, AgentPlugin, AgentCoreConfig, AgentListOptions, RegisterAgentData, UpdateAgentData, TransactionResult, JsonRpc, ProtonSession, PluginCategory, PaginatedResult, TrustScore } from './types';
2
+ export declare class AgentRegistry {
3
+ private rpc;
4
+ private session;
5
+ private contract;
6
+ constructor(rpc: JsonRpc, session?: ProtonSession, contract?: string);
7
+ /**
8
+ * Get a single agent by account name
9
+ */
10
+ getAgent(account: string): Promise<Agent | null>;
11
+ /**
12
+ * List all agents with optional filters and pagination
13
+ * @returns PaginatedResult with items, hasMore flag, and nextCursor for pagination
14
+ */
15
+ listAgents(options?: AgentListOptions): Promise<PaginatedResult<Agent>>;
16
+ /**
17
+ * Iterate through all agents with automatic pagination
18
+ */
19
+ listAgentsIterator(options?: Omit<AgentListOptions, 'cursor'>): AsyncGenerator<Agent>;
20
+ /**
21
+ * Get a plugin by ID
22
+ */
23
+ getPlugin(id: number): Promise<Plugin | null>;
24
+ /**
25
+ * List all plugins
26
+ */
27
+ listPlugins(category?: PluginCategory): Promise<Plugin[]>;
28
+ /**
29
+ * Get plugins assigned to an agent
30
+ */
31
+ getAgentPlugins(account: string): Promise<AgentPlugin[]>;
32
+ /**
33
+ * Get trust score for an agent (0-100)
34
+ * Combines KYC level, stake, reputation, and longevity
35
+ */
36
+ getTrustScore(account: string): Promise<TrustScore | null>;
37
+ /**
38
+ * Get contract configuration
39
+ */
40
+ getConfig(): Promise<AgentCoreConfig>;
41
+ /**
42
+ * Register a new agent
43
+ */
44
+ register(data: RegisterAgentData): Promise<TransactionResult>;
45
+ /**
46
+ * Register a new agent with registration fee in one transaction.
47
+ * Sends the fee deposit and registers in a single tx.
48
+ *
49
+ * @param data - Agent registration data
50
+ * @param amount - The registration fee (e.g., "1.0000 XPR")
51
+ */
52
+ registerWithFee(data: RegisterAgentData, amount: string): Promise<TransactionResult>;
53
+ /**
54
+ * Update agent metadata
55
+ */
56
+ update(data: UpdateAgentData): Promise<TransactionResult>;
57
+ /**
58
+ * Set agent active status
59
+ */
60
+ setStatus(active: boolean): Promise<TransactionResult>;
61
+ /**
62
+ * Add plugin to agent
63
+ */
64
+ addPlugin(pluginId: number, config?: object): Promise<TransactionResult>;
65
+ /**
66
+ * Remove plugin from agent
67
+ */
68
+ removePlugin(agentPluginId: number): Promise<TransactionResult>;
69
+ /**
70
+ * Register a new plugin
71
+ */
72
+ registerPlugin(name: string, version: string, contract: string, action: string, schema: object, category: PluginCategory): Promise<TransactionResult>;
73
+ /**
74
+ * Step 1: Agent approves a human to claim them.
75
+ * This is called by the AGENT to give consent.
76
+ *
77
+ * @param newOwner - The KYC'd human being approved to claim
78
+ */
79
+ approveClaim(newOwner: string): Promise<TransactionResult>;
80
+ /**
81
+ * Step 2: Human completes the claim after agent approval.
82
+ * Agent must have called approveClaim first.
83
+ *
84
+ * IMPORTANT: Before calling this, you must:
85
+ * 1. Have the agent call approveClaim(yourAccount)
86
+ * 2. Send the claim fee with memo "claim:agentname:yourname"
87
+ *
88
+ * @param agent - The agent account to claim
89
+ */
90
+ claim(agent: string): Promise<TransactionResult>;
91
+ /**
92
+ * Send claim fee and complete the claim in one transaction.
93
+ * Agent must have already called approveClaim first.
94
+ *
95
+ * @param agent - The agent account to claim
96
+ * @param amount - The claim fee amount (e.g., "1.0000 XPR")
97
+ */
98
+ claimWithFee(agent: string, amount: string): Promise<TransactionResult>;
99
+ /**
100
+ * Cancel a pending claim approval.
101
+ * Only the agent can cancel their own approval.
102
+ * Any deposit will be refunded to the payer.
103
+ *
104
+ * NOTE: The session holder must be the agent account.
105
+ */
106
+ cancelClaim(): Promise<TransactionResult>;
107
+ /**
108
+ * Transfer ownership of an agent to a new owner.
109
+ *
110
+ * IMPORTANT: The contract requires THREE signatures:
111
+ * 1. Current owner (must authorize)
112
+ * 2. New owner (must authorize)
113
+ * 3. Agent itself (must consent to the transfer)
114
+ *
115
+ * This method includes only the session holder's authorization.
116
+ * It will FAIL unless the session holder controls all three accounts,
117
+ * which is rare in practice.
118
+ *
119
+ * For most use cases, use `buildTransferProposal()` to create a multi-sig
120
+ * proposal that can be signed by all three parties.
121
+ *
122
+ * @param agent - The agent account
123
+ * @param newOwner - The new owner (must have KYC)
124
+ * @throws Will fail if session holder doesn't control all 3 required accounts
125
+ */
126
+ transferOwnership(agent: string, newOwner: string): Promise<TransactionResult>;
127
+ /**
128
+ * Build a transfer ownership action for use in a multi-sig proposal.
129
+ * Returns the action data that can be used with msig.propose.
130
+ *
131
+ * The transfer requires signatures from:
132
+ * 1. Current owner
133
+ * 2. New owner
134
+ * 3. Agent itself
135
+ *
136
+ * @param agent - The agent account
137
+ * @param currentOwner - The current owner account
138
+ * @param newOwner - The new owner account (must have KYC)
139
+ * @returns Action data for multi-sig proposal
140
+ */
141
+ buildTransferProposal(agent: string, currentOwner: string, newOwner: string): {
142
+ account: string;
143
+ name: string;
144
+ authorization: Array<{
145
+ actor: string;
146
+ permission: string;
147
+ }>;
148
+ data: {
149
+ agent: string;
150
+ new_owner: string;
151
+ };
152
+ };
153
+ /**
154
+ * Release ownership of an agent.
155
+ * Only the current owner can release.
156
+ * Claim deposit is refunded to the owner.
157
+ *
158
+ * @param agent - The agent account to release
159
+ */
160
+ release(agent: string): Promise<TransactionResult>;
161
+ /**
162
+ * Verify an agent's owner still has valid KYC.
163
+ * Anyone can call this to trigger re-verification.
164
+ *
165
+ * If the owner's KYC has dropped below level 1, the ownership
166
+ * is removed and the claim deposit is refunded to the former owner.
167
+ *
168
+ * This helps maintain trust score integrity by allowing community
169
+ * enforcement of KYC requirements.
170
+ *
171
+ * @param agent - The agent account to verify
172
+ */
173
+ verifyClaim(agent: string): Promise<TransactionResult>;
174
+ /**
175
+ * Get agents owned by a specific account
176
+ */
177
+ getAgentsByOwner(owner: string, limit?: number): Promise<Agent[]>;
178
+ private requireSession;
179
+ private parseAgent;
180
+ private parsePlugin;
181
+ private parseAgentPlugin;
182
+ }