@pixeloffice-eu/x402 1.0.1 → 1.0.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/README.md +17 -9
- package/bin/cli.js +2 -2
- package/index.js +13 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -14,20 +14,28 @@ npm install @pixeloffice-eu/x402
|
|
|
14
14
|
|
|
15
15
|
---
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## ⚡ Quickstart (Zero-Config with .env)
|
|
20
|
+
|
|
21
|
+
Put your agent's Solana key into your `.env`:
|
|
22
|
+
|
|
23
|
+
```env
|
|
24
|
+
# .env
|
|
25
|
+
SOLANA_PRIVATE_KEY=5K2...your_phantom_or_solana_base58_private_key...
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Then in your code:
|
|
18
29
|
|
|
19
30
|
```javascript
|
|
20
31
|
import { PixelRouterX402Client } from '@pixeloffice-eu/x402';
|
|
21
32
|
|
|
22
|
-
//
|
|
23
|
-
const client = new PixelRouterX402Client(
|
|
24
|
-
baseUrl: 'https://api.pixeloffice.eu/v1',
|
|
25
|
-
solanaPrivateKey: process.env.SOLANA_AGENT_PRIVATE_KEY
|
|
26
|
-
});
|
|
33
|
+
// Zero-config: Automatically picks up SOLANA_PRIVATE_KEY from process.env
|
|
34
|
+
const client = new PixelRouterX402Client();
|
|
27
35
|
|
|
28
|
-
// Autonomous LLM invocation with automatic HTTP 402
|
|
36
|
+
// Autonomous LLM invocation with automatic 0.24ms Solana HTTP 402 micro-settlement
|
|
29
37
|
const response = await client.createChatCompletion({
|
|
30
|
-
model: '
|
|
38
|
+
model: 'blun-auto', // Or 'deepseek-chat', 'claude-3.5-sonnet', 'ox-alpha'
|
|
31
39
|
messages: [
|
|
32
40
|
{ role: 'user', content: 'Execute autonomous codebase refactor.' }
|
|
33
41
|
]
|
|
@@ -52,7 +60,7 @@ const openai = wrapOpenAI(new OpenAI({
|
|
|
52
60
|
});
|
|
53
61
|
|
|
54
62
|
const completion = await openai.chat.completions.create({
|
|
55
|
-
model: '
|
|
63
|
+
model: 'blun-auto',
|
|
56
64
|
messages: [{ role: 'user', content: 'Hello autonomous world!' }]
|
|
57
65
|
});
|
|
58
66
|
```
|
package/bin/cli.js
CHANGED
|
@@ -29,9 +29,9 @@ async function runDirectAgent() {
|
|
|
29
29
|
sessionId: SESSION_ID
|
|
30
30
|
});
|
|
31
31
|
|
|
32
|
-
console.log('🧠 Invoking
|
|
32
|
+
console.log('🧠 Invoking BLUN-Auto (Sub-35ms Adaptive Routing & Optimization)...');
|
|
33
33
|
const response = await client.createChatCompletion({
|
|
34
|
-
model: '
|
|
34
|
+
model: 'blun-auto',
|
|
35
35
|
messages: [
|
|
36
36
|
{ role: 'system', content: 'You are an autonomous engineering agent.' },
|
|
37
37
|
{ role: 'user', content: 'Design an automated high-throughput data processing pipeline.' }
|
package/index.js
CHANGED
|
@@ -79,15 +79,24 @@ class PixelRouterX402Client {
|
|
|
79
79
|
this.sessionId = options.sessionId || null;
|
|
80
80
|
this.customSigner = options.customSigner || null;
|
|
81
81
|
|
|
82
|
+
// Auto-detect private/public key from environment if not explicitly passed
|
|
83
|
+
const envPrivKey = (typeof process !== 'undefined' && process.env) ?
|
|
84
|
+
(process.env.SOLANA_AGENT_PRIVATE_KEY || process.env.SOLANA_PRIVATE_KEY || process.env.SOLANA_KEY || null) : null;
|
|
85
|
+
const resolvedPrivKey = options.solanaPrivateKey || envPrivKey;
|
|
86
|
+
|
|
87
|
+
const envPubKey = (typeof process !== 'undefined' && process.env) ?
|
|
88
|
+
(process.env.SOLANA_AGENT_PUBLIC_KEY || process.env.SOLANA_PUBLIC_KEY || null) : null;
|
|
89
|
+
const resolvedPubKey = options.solanaPublicKey || envPubKey;
|
|
90
|
+
|
|
82
91
|
if (options.keypair && options.keypair.privateKey) {
|
|
83
92
|
this.privateKeyObject = options.keypair.privateKey;
|
|
84
93
|
this.publicKeyObject = options.keypair.publicKey;
|
|
85
94
|
const der = this.publicKeyObject.export({ type: 'spki', format: 'der' });
|
|
86
95
|
this.solanaPublicKey = bs58Encode(der.subarray(12));
|
|
87
|
-
} else if (
|
|
88
|
-
this._initFromPrivateKey(
|
|
96
|
+
} else if (resolvedPrivKey) {
|
|
97
|
+
this._initFromPrivateKey(resolvedPrivKey, resolvedPubKey);
|
|
89
98
|
} else if (options.customSigner) {
|
|
90
|
-
this.solanaPublicKey =
|
|
99
|
+
this.solanaPublicKey = resolvedPubKey || 'custom_signer_wallet';
|
|
91
100
|
} else {
|
|
92
101
|
// Create fresh ephemeral ed25519 keypair for autonomous agent
|
|
93
102
|
const kp = crypto.generateKeyPairSync('ed25519');
|
|
@@ -127,7 +136,7 @@ class PixelRouterX402Client {
|
|
|
127
136
|
async createChatCompletion(params = {}) {
|
|
128
137
|
const url = new URL(`${this.baseUrl}/chat/completions`);
|
|
129
138
|
const payload = JSON.stringify({
|
|
130
|
-
model: params.model || '
|
|
139
|
+
model: params.model || 'blun-auto',
|
|
131
140
|
messages: params.messages || [],
|
|
132
141
|
session_id: params.session_id || this.sessionId,
|
|
133
142
|
temperature: params.temperature || 0.7,
|