2020117-agent 0.3.1 → 0.3.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 +1 -1
- package/dist/agent.js +3 -0
- package/dist/api.d.ts +2 -0
- package/dist/api.js +23 -0
- package/dist/session.js +5 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@ npx 2020117-agent --kind=5302 --processor=exec:./translate.sh
|
|
|
15
15
|
npx 2020117-agent --kind=5200 --processor=http://localhost:7860 --models=sdxl-lightning,sd3.5-turbo
|
|
16
16
|
|
|
17
17
|
# P2P session — rent an agent by the minute
|
|
18
|
-
npx 2020117-session --kind=5200 --budget=500 --port=8080
|
|
18
|
+
npx -p 2020117-agent 2020117-session --kind=5200 --budget=500 --port=8080
|
|
19
19
|
```
|
|
20
20
|
|
|
21
21
|
## Setup
|
package/dist/agent.js
CHANGED
|
@@ -72,6 +72,9 @@ import { hasApiKey, loadAgentName, registerService, startHeartbeatLoop, getInbox
|
|
|
72
72
|
import { initClinkAgent, collectPayment } from './clink.js';
|
|
73
73
|
import { readFileSync } from 'fs';
|
|
74
74
|
import WebSocket from 'ws';
|
|
75
|
+
// Polyfill global WebSocket for Node.js < 22 (needed by @shocknet/clink-sdk)
|
|
76
|
+
if (!globalThis.WebSocket)
|
|
77
|
+
globalThis.WebSocket = WebSocket;
|
|
75
78
|
// --- Config from env ---
|
|
76
79
|
const KIND = Number(process.env.DVM_KIND) || 5100;
|
|
77
80
|
const MAX_CONCURRENT = Number(process.env.MAX_JOBS) || 3;
|
package/dist/api.d.ts
CHANGED
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
*/
|
|
8
8
|
/** Returns the resolved agent name from env or first key in file */
|
|
9
9
|
export declare function loadAgentName(): string | null;
|
|
10
|
+
/** Returns the ndebit from env or .2020117_keys file */
|
|
11
|
+
export declare function loadNdebit(): string | null;
|
|
10
12
|
export declare function hasApiKey(): boolean;
|
|
11
13
|
/** Fetch the authenticated agent's profile from the platform. */
|
|
12
14
|
export declare function getProfile(): Promise<{
|
package/dist/api.js
CHANGED
|
@@ -51,6 +51,29 @@ export function loadAgentName() {
|
|
|
51
51
|
}
|
|
52
52
|
return null;
|
|
53
53
|
}
|
|
54
|
+
/** Returns the ndebit from env or .2020117_keys file */
|
|
55
|
+
export function loadNdebit() {
|
|
56
|
+
if (process.env.CLINK_NDEBIT)
|
|
57
|
+
return process.env.CLINK_NDEBIT;
|
|
58
|
+
const agentName = process.env.AGENT_NAME || process.env.AGENT;
|
|
59
|
+
for (const dir of [process.cwd(), homedir()]) {
|
|
60
|
+
try {
|
|
61
|
+
const raw = readFileSync(join(dir, '.2020117_keys'), 'utf-8');
|
|
62
|
+
const keys = JSON.parse(raw);
|
|
63
|
+
if (agentName && keys[agentName]?.ndebit)
|
|
64
|
+
return keys[agentName].ndebit;
|
|
65
|
+
if (!agentName) {
|
|
66
|
+
const first = Object.values(keys)[0];
|
|
67
|
+
if (first?.ndebit)
|
|
68
|
+
return first.ndebit;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
// try next
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
54
77
|
const API_KEY = loadApiKey();
|
|
55
78
|
// --- Helpers ---
|
|
56
79
|
async function apiGet(path, auth = true) {
|
package/dist/session.js
CHANGED
|
@@ -44,16 +44,20 @@ for (const arg of process.argv.slice(2)) {
|
|
|
44
44
|
}
|
|
45
45
|
import { SwarmNode, topicFromKind } from './swarm.js';
|
|
46
46
|
import { queryProviderSkill } from './p2p-customer.js';
|
|
47
|
+
import { loadNdebit } from './api.js';
|
|
47
48
|
import { randomBytes } from 'crypto';
|
|
48
49
|
import { createServer } from 'http';
|
|
49
50
|
import { createInterface } from 'readline';
|
|
50
51
|
import { mkdirSync, writeFileSync } from 'fs';
|
|
51
52
|
import { WebSocketServer, WebSocket as WsWebSocket } from 'ws';
|
|
53
|
+
// Polyfill global WebSocket for Node.js < 22 (needed by @shocknet/clink-sdk)
|
|
54
|
+
if (!globalThis.WebSocket)
|
|
55
|
+
globalThis.WebSocket = WsWebSocket;
|
|
52
56
|
// --- Config ---
|
|
53
57
|
const KIND = Number(process.env.DVM_KIND) || 5200;
|
|
54
58
|
const BUDGET = Number(process.env.BUDGET_SATS) || 500;
|
|
55
59
|
const PORT = Number(process.env.SESSION_PORT) || 8080;
|
|
56
|
-
const NDEBIT = process.env.CLINK_NDEBIT || '';
|
|
60
|
+
const NDEBIT = process.env.CLINK_NDEBIT || loadNdebit() || '';
|
|
57
61
|
const TICK_INTERVAL_MS = 60_000;
|
|
58
62
|
const HTTP_TIMEOUT_MS = 60_000;
|
|
59
63
|
const state = {
|