2020117-agent 0.6.19 → 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 +25 -22
- 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,
|
|
@@ -322,8 +323,9 @@ async function publishProfile(label) {
|
|
|
322
323
|
if (!state.sovereignKeys || !state.relayPool)
|
|
323
324
|
return;
|
|
324
325
|
const agentName = state.agentName || 'sovereign-agent';
|
|
326
|
+
const displayName = state.skill?.name || agentName;
|
|
325
327
|
const content = {
|
|
326
|
-
name:
|
|
328
|
+
name: displayName,
|
|
327
329
|
about: state.skill?.description || `DVM agent (kind ${KIND})`,
|
|
328
330
|
picture: `https://robohash.org/${encodeURIComponent(agentName)}`,
|
|
329
331
|
};
|
|
@@ -342,8 +344,9 @@ async function publishHandlerInfo(label) {
|
|
|
342
344
|
if (!state.sovereignKeys || !state.relayPool)
|
|
343
345
|
return;
|
|
344
346
|
const agentName = state.agentName || 'sovereign-agent';
|
|
347
|
+
const displayName = state.skill?.name || agentName;
|
|
345
348
|
const content = {
|
|
346
|
-
name:
|
|
349
|
+
name: displayName,
|
|
347
350
|
about: state.skill?.description || `DVM agent (kind ${KIND})`,
|
|
348
351
|
pricing: { [String(KIND)]: SATS_PER_CHUNK * CHUNKS_PER_PAYMENT },
|
|
349
352
|
};
|
|
@@ -354,8 +357,8 @@ async function publishHandlerInfo(label) {
|
|
|
354
357
|
const event = signEvent({
|
|
355
358
|
kind: 31990,
|
|
356
359
|
tags: [
|
|
357
|
-
['d', `${agentName}-${
|
|
358
|
-
['k', String(
|
|
360
|
+
['d', `${agentName}-${KINDS.join('-')}`],
|
|
361
|
+
...KINDS.map(k => ['k', String(k)]),
|
|
359
362
|
],
|
|
360
363
|
content: JSON.stringify(content),
|
|
361
364
|
}, state.sovereignKeys.privkey);
|
|
@@ -379,13 +382,13 @@ function subscribeDvmRequests(label) {
|
|
|
379
382
|
if (dvmSubscribed)
|
|
380
383
|
return; // prevent double-subscribe (sovereign + platform both call this)
|
|
381
384
|
dvmSubscribed = true;
|
|
382
|
-
// Subscribe to all DVM requests of our kind (broadcast + directed)
|
|
383
|
-
state.relayPool.subscribe({ kinds:
|
|
385
|
+
// Subscribe to all DVM requests of our kind(s) (broadcast + directed)
|
|
386
|
+
state.relayPool.subscribe({ kinds: KINDS }, (event) => {
|
|
384
387
|
handleDvmRequest(label, event).catch(e => {
|
|
385
388
|
console.error(`[${label}] DVM request error: ${e.message}`);
|
|
386
389
|
});
|
|
387
390
|
});
|
|
388
|
-
console.log(`[${label}] Subscribed to DVM requests (Kind ${
|
|
391
|
+
console.log(`[${label}] Subscribed to DVM requests (Kind ${KINDS.join(',')}) via relay`);
|
|
389
392
|
}
|
|
390
393
|
// --- Customer: subscribe to DVM results and auto-pay ---
|
|
391
394
|
let dvmResultSubscribed = false;
|
|
@@ -396,13 +399,13 @@ function subscribeDvmResults(label) {
|
|
|
396
399
|
return;
|
|
397
400
|
dvmResultSubscribed = true;
|
|
398
401
|
// Subscribe to Kind 6xxx results directed to us (#p = our pubkey)
|
|
399
|
-
const
|
|
400
|
-
state.relayPool.subscribe({ kinds:
|
|
402
|
+
const resultKinds = KINDS.map(k => k + 1000);
|
|
403
|
+
state.relayPool.subscribe({ kinds: resultKinds, '#p': [state.sovereignKeys.pubkey] }, (event) => {
|
|
401
404
|
handleDvmResult(label, event).catch(e => {
|
|
402
405
|
console.error(`[${label}] DVM result handler error: ${e.message}`);
|
|
403
406
|
});
|
|
404
407
|
});
|
|
405
|
-
console.log(`[${label}] Subscribed to DVM results (Kind ${
|
|
408
|
+
console.log(`[${label}] Subscribed to DVM results (Kind ${resultKinds.join(',')}) via relay`);
|
|
406
409
|
}
|
|
407
410
|
async function handleDvmResult(label, event) {
|
|
408
411
|
if (!state.sovereignKeys || !state.relayPool)
|
|
@@ -651,7 +654,7 @@ async function handleDvmRequest(label, event) {
|
|
|
651
654
|
}
|
|
652
655
|
console.log(`[${label}] DVM result: ${result.length} chars`);
|
|
653
656
|
// Send result (Kind 6xxx = request kind + 1000)
|
|
654
|
-
const resultKind =
|
|
657
|
+
const resultKind = event.kind + 1000;
|
|
655
658
|
// Prefer the bid the customer declared in the job; fall back to local fixed price.
|
|
656
659
|
// bid tag is in the outer (unencrypted) event tags per NIP-90.
|
|
657
660
|
const bidMsats = Number(event.tags.find(t => t[0] === 'bid')?.[1] || '0');
|
|
@@ -746,7 +749,7 @@ function startNostrHeartbeat(label, keys, pool, opts) {
|
|
|
746
749
|
['d', keys.pubkey],
|
|
747
750
|
['status', 'online'],
|
|
748
751
|
['capacity', String(getAvailableCapacity())],
|
|
749
|
-
['kinds',
|
|
752
|
+
['kinds', KINDS.join(',')],
|
|
750
753
|
];
|
|
751
754
|
// Add pricing tag (format: "5100:50,5200:100")
|
|
752
755
|
if (opts?.pricing && Object.keys(opts.pricing).length > 0) {
|