@x1scroll/agent-sdk 1.0.1 → 1.0.2
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 +6 -13
- package/package.json +1 -1
- package/src/index.js +21 -45
package/README.md
CHANGED
|
@@ -122,29 +122,22 @@ const { txSig, memoryEntryPDA } = await client.storeMemory(
|
|
|
122
122
|
|
|
123
123
|
**Fee:** 0.001 XNT (same as `storeMemory`)
|
|
124
124
|
|
|
125
|
-
|
|
126
|
-
// Using x1scroll.io IPFS (free, rate-limited — good for dev/testing)
|
|
127
|
-
const { txSig, cid } = await client.uploadMemory(
|
|
128
|
-
agentKeypair,
|
|
129
|
-
humanWallet.publicKey.toBase58(),
|
|
130
|
-
'session-2026-04-06',
|
|
131
|
-
{ summary: 'Discussed SDK launch', decisions: ['publish to npm', 'BSL license'] }
|
|
132
|
-
);
|
|
125
|
+
Requires a free [Pinata](https://pinata.cloud) API key (free tier: 100 pins, 1GB — enough for development and testing).
|
|
133
126
|
|
|
134
|
-
|
|
127
|
+
```js
|
|
135
128
|
const { txSig, cid } = await client.uploadMemory(
|
|
136
129
|
agentKeypair,
|
|
137
130
|
humanWallet.publicKey.toBase58(),
|
|
138
131
|
'session-2026-04-06',
|
|
139
|
-
{ summary: 'Discussed SDK launch' },
|
|
140
|
-
{
|
|
132
|
+
{ summary: 'Discussed SDK launch', decisions: ['publish to npm', 'BSL license'] },
|
|
133
|
+
{ pinataJwt: process.env.PINATA_JWT, tags: ['session', 'daily'] }
|
|
141
134
|
);
|
|
135
|
+
// Content is pinned on IPFS, CID stored on X1. Done.
|
|
142
136
|
```
|
|
143
137
|
|
|
144
138
|
| Option | Type | Default | Description |
|
|
145
139
|
|--------|------|---------|-------------|
|
|
146
|
-
| `
|
|
147
|
-
| `pinataJwt` | `string` | — | Required if provider is `'pinata'` |
|
|
140
|
+
| `pinataJwt` | `string` | — | **Required.** Get free at pinata.cloud |
|
|
148
141
|
| `tags` | `string[]` | `[]` | Up to 5 tags |
|
|
149
142
|
| `encrypted` | `boolean` | `false` | Whether content is encrypted |
|
|
150
143
|
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -551,62 +551,38 @@ class AgentClient {
|
|
|
551
551
|
*/
|
|
552
552
|
async uploadMemory(agentKeypair, agentRecordHuman, topic, content, options = {}) {
|
|
553
553
|
const {
|
|
554
|
-
provider = 'x1scroll',
|
|
555
554
|
pinataJwt = null,
|
|
556
555
|
tags = [],
|
|
557
556
|
encrypted = false,
|
|
558
557
|
} = options;
|
|
559
558
|
|
|
559
|
+
if (!pinataJwt) {
|
|
560
|
+
throw new AgentSDKError(
|
|
561
|
+
'pinataJwt is required for uploadMemory(). Get a free API key at https://pinata.cloud (free tier: 100 pins, 1GB). Pass it as options.pinataJwt.',
|
|
562
|
+
'MISSING_PINATA_JWT'
|
|
563
|
+
);
|
|
564
|
+
}
|
|
565
|
+
|
|
560
566
|
// Serialize content
|
|
561
567
|
const body = (typeof content === 'string') ? content : JSON.stringify(content);
|
|
562
568
|
|
|
563
569
|
let cid;
|
|
564
570
|
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
'Authorization': `Bearer ${pinataJwt}`,
|
|
578
|
-
},
|
|
579
|
-
body: JSON.stringify({ pinataContent: body, pinataMetadata: { name: topic } }),
|
|
580
|
-
});
|
|
581
|
-
if (!res.ok) {
|
|
582
|
-
const err = await res.text();
|
|
583
|
-
throw new AgentSDKError(`Pinata upload failed: ${err}`, 'PINATA_ERROR');
|
|
584
|
-
}
|
|
585
|
-
const json = await res.json();
|
|
586
|
-
cid = json.IpfsHash;
|
|
587
|
-
|
|
588
|
-
} else if (provider === 'x1scroll') {
|
|
589
|
-
// Upload to x1scroll.io IPFS node (free, rate-limited)
|
|
590
|
-
const res = await fetch('https://ipfs.x1scroll.io/upload', {
|
|
591
|
-
method: 'POST',
|
|
592
|
-
headers: { 'Content-Type': 'application/json' },
|
|
593
|
-
body: JSON.stringify({ content: body, topic, agentPubkey: agentKeypair.publicKey.toBase58() }),
|
|
594
|
-
});
|
|
595
|
-
if (!res.ok) {
|
|
596
|
-
throw new AgentSDKError(
|
|
597
|
-
`x1scroll IPFS upload failed (${res.status}). Use provider='pinata' for production workloads.`,
|
|
598
|
-
'X1SCROLL_IPFS_ERROR'
|
|
599
|
-
);
|
|
600
|
-
}
|
|
601
|
-
const json = await res.json();
|
|
602
|
-
cid = json.cid;
|
|
603
|
-
|
|
604
|
-
} else {
|
|
605
|
-
throw new AgentSDKError(
|
|
606
|
-
`Unknown provider "${provider}". Supported: 'pinata', 'x1scroll'`,
|
|
607
|
-
'INVALID_PROVIDER'
|
|
608
|
-
);
|
|
571
|
+
// Upload to Pinata — auto-pinned, persistent
|
|
572
|
+
const res = await fetch('https://api.pinata.cloud/pinning/pinJSONToIPFS', {
|
|
573
|
+
method: 'POST',
|
|
574
|
+
headers: {
|
|
575
|
+
'Content-Type': 'application/json',
|
|
576
|
+
'Authorization': `Bearer ${pinataJwt}`,
|
|
577
|
+
},
|
|
578
|
+
body: JSON.stringify({ pinataContent: body, pinataMetadata: { name: topic } }),
|
|
579
|
+
});
|
|
580
|
+
if (!res.ok) {
|
|
581
|
+
const err = await res.text();
|
|
582
|
+
throw new AgentSDKError(`Pinata upload failed: ${err}`, 'PINATA_ERROR');
|
|
609
583
|
}
|
|
584
|
+
const json = await res.json();
|
|
585
|
+
cid = json.IpfsHash;
|
|
610
586
|
|
|
611
587
|
if (!cid) {
|
|
612
588
|
throw new AgentSDKError('IPFS upload returned no CID', 'NO_CID');
|