@gholl-studio/pier-connector 0.1.0 → 0.1.1
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/package.json +1 -1
- package/src/index.js +50 -21
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gholl-studio/pier-connector",
|
|
3
3
|
"author": "gholl",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.1",
|
|
5
5
|
"description": "OpenClaw plugin that connects to the Pier job marketplace. Automatically fetches, executes, and reports distributed tasks for rewards.",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "src/index.js",
|
package/src/index.js
CHANGED
|
@@ -49,7 +49,8 @@ export default function register(api) {
|
|
|
49
49
|
|
|
50
50
|
/** @type {Map<string, import('@nats-io/transport-node').Subscription>} */
|
|
51
51
|
const jobSubscriptions = new Map();
|
|
52
|
-
const jobStopTimeouts = new Map();
|
|
52
|
+
const jobStopTimeouts = new Map();
|
|
53
|
+
const activeNodeJobs = new Map();
|
|
53
54
|
|
|
54
55
|
// ── resolve plugin config ──────────────────────────────────────────
|
|
55
56
|
|
|
@@ -148,15 +149,10 @@ const jobStopTimeouts = new Map();
|
|
|
148
149
|
accountId: accountId ?? 'default',
|
|
149
150
|
enabled: true,
|
|
150
151
|
},
|
|
152
|
+
isConfigured: (account) => Boolean(account.nodeId && account.secretKey) || Boolean(account.privateKey),
|
|
151
153
|
},
|
|
152
154
|
|
|
153
155
|
setup: {
|
|
154
|
-
checkAccountStatus: async ({ accountId }) => {
|
|
155
|
-
if (connectionStatus === 'connected') return { status: 'connected' };
|
|
156
|
-
if (connectionStatus === 'error') return { status: 'error', details: 'NATS connection error' };
|
|
157
|
-
if (connectionStatus === 'connecting') return { status: 'connecting' };
|
|
158
|
-
return { status: 'disconnected', details: connectionStatus };
|
|
159
|
-
},
|
|
160
156
|
applyAccountConfig: ({ cfg, accountId, input }) => {
|
|
161
157
|
const draft = structuredClone(cfg);
|
|
162
158
|
draft.channels = draft.channels || {};
|
|
@@ -188,7 +184,15 @@ const jobStopTimeouts = new Map();
|
|
|
188
184
|
* Send a reply text back through the NATS response.
|
|
189
185
|
* This is called by OpenClaw's agent after processing a job.
|
|
190
186
|
*/
|
|
191
|
-
sendText: async (
|
|
187
|
+
sendText: async (ctx) => {
|
|
188
|
+
const text = ctx.text;
|
|
189
|
+
let metadata = ctx.metadata;
|
|
190
|
+
|
|
191
|
+
if (!metadata && ctx.to) {
|
|
192
|
+
const toId = ctx.to.replace(/^pier:/, '');
|
|
193
|
+
metadata = activeNodeJobs.get(toId);
|
|
194
|
+
}
|
|
195
|
+
|
|
192
196
|
const jobId = metadata?.pierJobId;
|
|
193
197
|
const msg = metadata?.pierNatsMsg;
|
|
194
198
|
const isRealtimeMsg = metadata?.isRealtimeMsg;
|
|
@@ -244,7 +248,7 @@ const jobStopTimeouts = new Map();
|
|
|
244
248
|
jobSubscriptions.delete(jobId);
|
|
245
249
|
jobStopTimeouts.delete(jobId);
|
|
246
250
|
}
|
|
247
|
-
},
|
|
251
|
+
}, 3600000); // 1 hour inactivity timeout
|
|
248
252
|
|
|
249
253
|
jobStopTimeouts.set(jobId, timeout);
|
|
250
254
|
}
|
|
@@ -253,6 +257,24 @@ const jobStopTimeouts = new Map();
|
|
|
253
257
|
return { ok: true };
|
|
254
258
|
},
|
|
255
259
|
},
|
|
260
|
+
|
|
261
|
+
status: {
|
|
262
|
+
defaultRuntime: {
|
|
263
|
+
accountId: 'default',
|
|
264
|
+
running: false,
|
|
265
|
+
connected: false,
|
|
266
|
+
},
|
|
267
|
+
buildAccountSnapshot: ({ account }) => {
|
|
268
|
+
return {
|
|
269
|
+
accountId: account.accountId,
|
|
270
|
+
name: account.name,
|
|
271
|
+
enabled: account.enabled,
|
|
272
|
+
configured: Boolean(account.nodeId && account.secretKey) || Boolean(account.privateKey),
|
|
273
|
+
running: connectionStatus === 'connected' || connectionStatus === 'connecting',
|
|
274
|
+
connected: connectionStatus === 'connected',
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
},
|
|
256
278
|
};
|
|
257
279
|
|
|
258
280
|
api.registerChannel({ plugin: pierChannel });
|
|
@@ -473,15 +495,18 @@ const jobStopTimeouts = new Map();
|
|
|
473
495
|
const content = msgPayload.content;
|
|
474
496
|
logger.info(`[pier-connector] 💬 Message for job ${jobId}: "${truncate(content, 40)}"`);
|
|
475
497
|
|
|
498
|
+
const senderCore = msgPayload.sender_id;
|
|
499
|
+
|
|
500
|
+
activeNodeJobs.set(senderCore, {
|
|
501
|
+
pierJobId: jobId,
|
|
502
|
+
isRealtimeMsg: true
|
|
503
|
+
});
|
|
504
|
+
|
|
476
505
|
await api.runtime.sendIncoming({
|
|
477
506
|
channelId: 'pier',
|
|
478
507
|
accountId: config.accountId || 'default',
|
|
479
|
-
senderId: `pier:${
|
|
508
|
+
senderId: `pier:${senderCore}`,
|
|
480
509
|
text: content,
|
|
481
|
-
metadata: {
|
|
482
|
-
pierJobId: jobId,
|
|
483
|
-
isRealtimeMsg: true
|
|
484
|
-
}
|
|
485
510
|
});
|
|
486
511
|
}
|
|
487
512
|
} catch (err) {
|
|
@@ -537,18 +562,22 @@ const jobStopTimeouts = new Map();
|
|
|
537
562
|
logger.info(`[pier-connector] 📥 Received job ${job.id}: "${truncate(job.task, 60)}"`);
|
|
538
563
|
|
|
539
564
|
try {
|
|
565
|
+
const senderCore = job.meta?.sender ?? 'anonymous';
|
|
566
|
+
|
|
567
|
+
activeNodeJobs.set(senderCore, {
|
|
568
|
+
pierJobId: job.id,
|
|
569
|
+
pierNatsMsg: msg,
|
|
570
|
+
pierStartTime: startTime,
|
|
571
|
+
pierMeta: job.meta,
|
|
572
|
+
isRealtimeMsg: false
|
|
573
|
+
});
|
|
574
|
+
|
|
540
575
|
const inbound = {
|
|
541
576
|
channelId: 'pier',
|
|
542
577
|
accountId: config.accountId || 'default',
|
|
543
|
-
senderId: `pier:${
|
|
578
|
+
senderId: `pier:${senderCore}`,
|
|
544
579
|
text: job.task,
|
|
545
580
|
assignedAgentId: config.agentId || undefined,
|
|
546
|
-
metadata: {
|
|
547
|
-
pierJobId: job.id,
|
|
548
|
-
pierNatsMsg: msg,
|
|
549
|
-
pierStartTime: startTime,
|
|
550
|
-
pierMeta: job.meta,
|
|
551
|
-
},
|
|
552
581
|
};
|
|
553
582
|
|
|
554
583
|
if (job.systemPrompt) inbound.systemPrompt = job.systemPrompt;
|