@gholl-studio/pier-connector 0.2.26 → 0.2.28
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 +20 -45
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gholl-studio/pier-connector",
|
|
3
3
|
"author": "gholl",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.28",
|
|
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
|
@@ -259,40 +259,33 @@ export default function register(api) {
|
|
|
259
259
|
if (!this.js) return;
|
|
260
260
|
|
|
261
261
|
const chatSubject = `chat.${jobId}`;
|
|
262
|
-
const actionSubject = `jobs.action.${jobId}`;
|
|
263
262
|
const streamName = 'PIER_JOBS';
|
|
264
263
|
const nodeSlug = this.config.nodeId.replace(/[^a-zA-Z0-9]/g, '_');
|
|
265
264
|
const jobSlug = jobId.replace(/[^a-zA-Z0-9]/g, '_');
|
|
266
|
-
|
|
267
|
-
const chatDurable = `pier_chat_${nodeSlug}_${jobSlug}`;
|
|
268
|
-
const actionDurable = `pier_action_${nodeSlug}_${jobSlug}`;
|
|
265
|
+
const durableName = `pier_chat_${nodeSlug}_${jobSlug}`;
|
|
269
266
|
|
|
270
|
-
|
|
267
|
+
try {
|
|
271
268
|
let consumer;
|
|
272
269
|
try {
|
|
273
|
-
consumer = await this.js.consumers.get(streamName,
|
|
270
|
+
consumer = await this.js.consumers.get(streamName, durableName);
|
|
274
271
|
} catch {
|
|
275
272
|
await this.jsm.consumers.add(streamName, {
|
|
276
|
-
durable_name:
|
|
277
|
-
filter_subject:
|
|
273
|
+
durable_name: durableName,
|
|
274
|
+
filter_subject: chatSubject,
|
|
278
275
|
deliver_policy: DeliverPolicy.New,
|
|
279
276
|
ack_policy: AckPolicy.Explicit,
|
|
280
277
|
ack_wait: 1000 * 60 * 60,
|
|
281
278
|
});
|
|
282
|
-
consumer = await this.js.consumers.get(streamName,
|
|
279
|
+
consumer = await this.js.consumers.get(streamName, durableName);
|
|
283
280
|
}
|
|
284
|
-
return consumer;
|
|
285
|
-
};
|
|
286
281
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
const chatIter = await chatConsumer.consume();
|
|
291
|
-
|
|
282
|
+
const iter = await consumer.consume();
|
|
283
|
+
this.jobSubscriptions.set(jobId, iter);
|
|
284
|
+
|
|
292
285
|
(async () => {
|
|
293
|
-
logger.info(`[pier-connector][${this.accountId}]
|
|
286
|
+
logger.info(`[pier-connector][${this.accountId}] \u{1F442} Monitoring ${chatSubject}`);
|
|
294
287
|
const processedMessages = new Set();
|
|
295
|
-
for await (const msg of
|
|
288
|
+
for await (const msg of iter) {
|
|
296
289
|
try {
|
|
297
290
|
const rawMsg = new TextDecoder().decode(msg.data);
|
|
298
291
|
let msgPayload = JSON.parse(rawMsg);
|
|
@@ -300,6 +293,8 @@ export default function register(api) {
|
|
|
300
293
|
if (msgPayload.id && processedMessages.has(msgPayload.id)) { msg.ack(); continue; }
|
|
301
294
|
if (msgPayload.sender_id === this.config.nodeId) { msg.ack(); continue; }
|
|
302
295
|
if (msgPayload.type === 'receipt') { msg.ack(); continue; }
|
|
296
|
+
// Skip system_action messages — those are for the backend state machine
|
|
297
|
+
if (msgPayload.type === 'system_action' || msgPayload.msg_type === 'system_action') { msg.ack(); continue; }
|
|
303
298
|
|
|
304
299
|
// Send receipt
|
|
305
300
|
try {
|
|
@@ -311,7 +306,7 @@ export default function register(api) {
|
|
|
311
306
|
const content = msgPayload.content;
|
|
312
307
|
if (!content) { msg.ack(); continue; }
|
|
313
308
|
|
|
314
|
-
logger.info(`[pier-connector][${this.accountId}]
|
|
309
|
+
logger.info(`[pier-connector][${this.accountId}] \u{1F4AC} Chat: [${jobId}] ${msgPayload.sender_id}: "${truncate(content, 40)}"`);
|
|
315
310
|
if (msgPayload.id) processedMessages.add(msgPayload.id);
|
|
316
311
|
msg.ack();
|
|
317
312
|
|
|
@@ -323,27 +318,8 @@ export default function register(api) {
|
|
|
323
318
|
} catch (err) { logger.error(`[pier-connector] Chat err: ${err.message}`); }
|
|
324
319
|
}
|
|
325
320
|
})();
|
|
326
|
-
|
|
327
|
-
// 2. Setup Action Consumer (System Signal)
|
|
328
|
-
const actionConsumer = await setupConsumer(actionSubject, actionDurable);
|
|
329
|
-
const actionIter = await actionConsumer.consume();
|
|
330
|
-
|
|
331
|
-
(async () => {
|
|
332
|
-
logger.info(`[pier-connector][${this.accountId}] ⚙️ Monitoring ACTION subject ${actionSubject}`);
|
|
333
|
-
for await (const msg of actionIter) {
|
|
334
|
-
try {
|
|
335
|
-
const rawMsg = new TextDecoder().decode(msg.data);
|
|
336
|
-
let payload = JSON.parse(rawMsg);
|
|
337
|
-
logger.info(`[pier-connector][${this.accountId}] 📥 Action: [${jobId}] ${payload.action || 'signal'}`);
|
|
338
|
-
msg.ack();
|
|
339
|
-
// Implementation of system action handling logic on the node side if needed.
|
|
340
|
-
} catch (err) { logger.error(`[pier-connector] Action err: ${err.message}`); }
|
|
341
|
-
}
|
|
342
|
-
})();
|
|
343
|
-
|
|
344
|
-
this.jobSubscriptions.set(jobId, { chat: chatIter, action: actionIter });
|
|
345
321
|
} catch (err) {
|
|
346
|
-
logger.error(`[pier-connector][${this.accountId}] Failed to setup
|
|
322
|
+
logger.error(`[pier-connector][${this.accountId}] Failed to setup chat consumer: ${err.message}`);
|
|
347
323
|
}
|
|
348
324
|
}
|
|
349
325
|
|
|
@@ -641,11 +617,10 @@ export default function register(api) {
|
|
|
641
617
|
if (robot.jobStopTimeouts.has(jobId)) clearTimeout(robot.jobStopTimeouts.get(jobId));
|
|
642
618
|
|
|
643
619
|
const timeout = setTimeout(() => {
|
|
644
|
-
const
|
|
645
|
-
if (
|
|
646
|
-
logger.info(`[pier-connector][${accountId}]
|
|
647
|
-
|
|
648
|
-
if (subs.action) subs.action.stop();
|
|
620
|
+
const sub = robot.jobSubscriptions.get(jobId);
|
|
621
|
+
if (sub) {
|
|
622
|
+
logger.info(`[pier-connector][${accountId}] \u{1F6D1} Stopping listener for job ${jobId} (inactivity)`);
|
|
623
|
+
sub.stop();
|
|
649
624
|
robot.jobSubscriptions.delete(jobId);
|
|
650
625
|
robot.jobStopTimeouts.delete(jobId);
|
|
651
626
|
}
|
|
@@ -819,7 +794,7 @@ export default function register(api) {
|
|
|
819
794
|
}
|
|
820
795
|
|
|
821
796
|
try {
|
|
822
|
-
const subject = `
|
|
797
|
+
const subject = `chat.${params.jobId}`;
|
|
823
798
|
const { jobId, accountId: _, ...payload } = params;
|
|
824
799
|
|
|
825
800
|
const msgData = {
|