2020117-agent 0.6.20 → 0.6.21
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/dist/agent.d.ts +5 -5
- package/dist/agent.js +21 -20
- package/package.json +1 -1
package/dist/agent.d.ts
CHANGED
|
@@ -8,10 +8,10 @@
|
|
|
8
8
|
* to relays. The platform API is only used for read operations (pipeline sub-tasks).
|
|
9
9
|
*
|
|
10
10
|
* Usage:
|
|
11
|
-
* AGENT=translator DVM_KIND=
|
|
12
|
-
* AGENT=my-agent DVM_KIND=
|
|
13
|
-
* AGENT=broker DVM_KIND=
|
|
14
|
-
* AGENT=custom DVM_KIND=
|
|
15
|
-
* AGENT=remote DVM_KIND=
|
|
11
|
+
* AGENT=translator DVM_KIND=5002 OLLAMA_MODEL=qwen2.5:0.5b npm run agent
|
|
12
|
+
* AGENT=my-agent DVM_KIND=5050 MAX_JOBS=5 npm run agent
|
|
13
|
+
* AGENT=broker DVM_KIND=5002 PROCESSOR=none SUB_KIND=5050 npm run agent
|
|
14
|
+
* AGENT=custom DVM_KIND=5050 PROCESSOR=exec:./my-model.sh npm run agent
|
|
15
|
+
* AGENT=remote DVM_KIND=5050 PROCESSOR=http://localhost:8080 npm run agent
|
|
16
16
|
*/
|
|
17
17
|
export {};
|
package/dist/agent.js
CHANGED
|
@@ -8,11 +8,11 @@
|
|
|
8
8
|
* to relays. The platform API is only used for read operations (pipeline sub-tasks).
|
|
9
9
|
*
|
|
10
10
|
* Usage:
|
|
11
|
-
* AGENT=translator DVM_KIND=
|
|
12
|
-
* AGENT=my-agent DVM_KIND=
|
|
13
|
-
* AGENT=broker DVM_KIND=
|
|
14
|
-
* AGENT=custom DVM_KIND=
|
|
15
|
-
* AGENT=remote DVM_KIND=
|
|
11
|
+
* AGENT=translator DVM_KIND=5002 OLLAMA_MODEL=qwen2.5:0.5b npm run agent
|
|
12
|
+
* AGENT=my-agent DVM_KIND=5050 MAX_JOBS=5 npm run agent
|
|
13
|
+
* AGENT=broker DVM_KIND=5002 PROCESSOR=none SUB_KIND=5050 npm run agent
|
|
14
|
+
* AGENT=custom DVM_KIND=5050 PROCESSOR=exec:./my-model.sh npm run agent
|
|
15
|
+
* AGENT=remote DVM_KIND=5050 PROCESSOR=http://localhost:8080 npm run agent
|
|
16
16
|
*/
|
|
17
17
|
// --- CLI args → env (for npx usage) ---
|
|
18
18
|
for (const arg of process.argv.slice(2)) {
|
|
@@ -91,7 +91,8 @@ import WebSocket from 'ws';
|
|
|
91
91
|
if (!globalThis.WebSocket)
|
|
92
92
|
globalThis.WebSocket = WebSocket;
|
|
93
93
|
// --- Config from env ---
|
|
94
|
-
const
|
|
94
|
+
const KINDS = (process.env.DVM_KIND || '5050').split(',').map(s => Number(s.trim())).filter(Boolean);
|
|
95
|
+
const KIND = KINDS[0]; // primary kind (for result subscriptions, registration, etc.)
|
|
95
96
|
const MAX_CONCURRENT = Number(process.env.MAX_JOBS) || 3;
|
|
96
97
|
const P2P_ONLY = process.env.P2P_ONLY === 'true' || process.env.P2P_ONLY === '1';
|
|
97
98
|
const SATS_PER_CHUNK = Number(process.env.SATS_PER_CHUNK) || 1;
|
|
@@ -161,7 +162,7 @@ async function main() {
|
|
|
161
162
|
console.log(`[${label}] Starting agent runtime`);
|
|
162
163
|
// 1. Create and verify processor
|
|
163
164
|
state.processor = await createProcessor();
|
|
164
|
-
console.log(`[${label}] kind=${
|
|
165
|
+
console.log(`[${label}] kind=${KINDS.join(',')} processor=${state.processor.name} maxJobs=${MAX_CONCURRENT}`);
|
|
165
166
|
if (SUB_KIND) {
|
|
166
167
|
console.log(`[${label}] Pipeline: sub-task kind=${SUB_KIND} (bid=${SUB_BID}${SUB_PROVIDER ? `, provider=${SUB_PROVIDER}` : ''})`);
|
|
167
168
|
}
|
|
@@ -266,7 +267,7 @@ async function setupNostr(label) {
|
|
|
266
267
|
const pricing = {};
|
|
267
268
|
const priceSats = SATS_PER_CHUNK * CHUNKS_PER_PAYMENT;
|
|
268
269
|
if (priceSats > 0)
|
|
269
|
-
pricing[String(
|
|
270
|
+
KINDS.forEach(k => { pricing[String(k)] = priceSats; });
|
|
270
271
|
state.stopHeartbeat = startNostrHeartbeat(label, state.sovereignKeys, state.relayPool, {
|
|
271
272
|
pricing,
|
|
272
273
|
p2pStatsFn: () => ({
|
|
@@ -281,7 +282,7 @@ async function setupNostr(label) {
|
|
|
281
282
|
console.log(`═══════════════════════════════════════════════`);
|
|
282
283
|
console.log(` Agent ready: ${agentName}`);
|
|
283
284
|
console.log(` Pubkey: ${keys.pubkey}`);
|
|
284
|
-
console.log(` Kind: ${
|
|
285
|
+
console.log(` Kind: ${KINDS.join(',')}`);
|
|
285
286
|
console.log(` Relays: ${relays}`);
|
|
286
287
|
console.log(` Lightning: ${LIGHTNING_ADDRESS || '(not set)'}`);
|
|
287
288
|
console.log(` NWC wallet: ${state.nwcParsed ? 'connected' : '(not set)'}`);
|
|
@@ -300,7 +301,7 @@ async function publishAiInfo(label) {
|
|
|
300
301
|
supported_models: state.processor?.name ? [state.processor.name] : [],
|
|
301
302
|
default_model: state.processor?.name || 'default',
|
|
302
303
|
dvm_compatible: true,
|
|
303
|
-
dvm_kinds:
|
|
304
|
+
dvm_kinds: KINDS,
|
|
304
305
|
pricing_hints: {
|
|
305
306
|
currency: 'BTC',
|
|
306
307
|
sats_per_prompt: SATS_PER_CHUNK * CHUNKS_PER_PAYMENT,
|
|
@@ -356,8 +357,8 @@ async function publishHandlerInfo(label) {
|
|
|
356
357
|
const event = signEvent({
|
|
357
358
|
kind: 31990,
|
|
358
359
|
tags: [
|
|
359
|
-
['d', `${agentName}-${
|
|
360
|
-
['k', String(
|
|
360
|
+
['d', `${agentName}-${KINDS.join('-')}`],
|
|
361
|
+
...KINDS.map(k => ['k', String(k)]),
|
|
361
362
|
],
|
|
362
363
|
content: JSON.stringify(content),
|
|
363
364
|
}, state.sovereignKeys.privkey);
|
|
@@ -381,13 +382,13 @@ function subscribeDvmRequests(label) {
|
|
|
381
382
|
if (dvmSubscribed)
|
|
382
383
|
return; // prevent double-subscribe (sovereign + platform both call this)
|
|
383
384
|
dvmSubscribed = true;
|
|
384
|
-
// Subscribe to all DVM requests of our kind (broadcast + directed)
|
|
385
|
-
state.relayPool.subscribe({ kinds:
|
|
385
|
+
// Subscribe to all DVM requests of our kind(s) (broadcast + directed)
|
|
386
|
+
state.relayPool.subscribe({ kinds: KINDS }, (event) => {
|
|
386
387
|
handleDvmRequest(label, event).catch(e => {
|
|
387
388
|
console.error(`[${label}] DVM request error: ${e.message}`);
|
|
388
389
|
});
|
|
389
390
|
});
|
|
390
|
-
console.log(`[${label}] Subscribed to DVM requests (Kind ${
|
|
391
|
+
console.log(`[${label}] Subscribed to DVM requests (Kind ${KINDS.join(',')}) via relay`);
|
|
391
392
|
}
|
|
392
393
|
// --- Customer: subscribe to DVM results and auto-pay ---
|
|
393
394
|
let dvmResultSubscribed = false;
|
|
@@ -398,13 +399,13 @@ function subscribeDvmResults(label) {
|
|
|
398
399
|
return;
|
|
399
400
|
dvmResultSubscribed = true;
|
|
400
401
|
// Subscribe to Kind 6xxx results directed to us (#p = our pubkey)
|
|
401
|
-
const
|
|
402
|
-
state.relayPool.subscribe({ kinds:
|
|
402
|
+
const resultKinds = KINDS.map(k => k + 1000);
|
|
403
|
+
state.relayPool.subscribe({ kinds: resultKinds, '#p': [state.sovereignKeys.pubkey] }, (event) => {
|
|
403
404
|
handleDvmResult(label, event).catch(e => {
|
|
404
405
|
console.error(`[${label}] DVM result handler error: ${e.message}`);
|
|
405
406
|
});
|
|
406
407
|
});
|
|
407
|
-
console.log(`[${label}] Subscribed to DVM results (Kind ${
|
|
408
|
+
console.log(`[${label}] Subscribed to DVM results (Kind ${resultKinds.join(',')}) via relay`);
|
|
408
409
|
}
|
|
409
410
|
async function handleDvmResult(label, event) {
|
|
410
411
|
if (!state.sovereignKeys || !state.relayPool)
|
|
@@ -653,7 +654,7 @@ async function handleDvmRequest(label, event) {
|
|
|
653
654
|
}
|
|
654
655
|
console.log(`[${label}] DVM result: ${result.length} chars`);
|
|
655
656
|
// Send result (Kind 6xxx = request kind + 1000)
|
|
656
|
-
const resultKind =
|
|
657
|
+
const resultKind = event.kind + 1000;
|
|
657
658
|
// Prefer the bid the customer declared in the job; fall back to local fixed price.
|
|
658
659
|
// bid tag is in the outer (unencrypted) event tags per NIP-90.
|
|
659
660
|
const bidMsats = Number(event.tags.find(t => t[0] === 'bid')?.[1] || '0');
|
|
@@ -748,7 +749,7 @@ function startNostrHeartbeat(label, keys, pool, opts) {
|
|
|
748
749
|
['d', keys.pubkey],
|
|
749
750
|
['status', 'online'],
|
|
750
751
|
['capacity', String(getAvailableCapacity())],
|
|
751
|
-
['kinds',
|
|
752
|
+
['kinds', KINDS.join(',')],
|
|
752
753
|
];
|
|
753
754
|
// Add pricing tag (format: "5100:50,5200:100")
|
|
754
755
|
if (opts?.pricing && Object.keys(opts.pricing).length > 0) {
|