@gholl-studio/pier-connector 0.2.28 → 0.2.30
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 +31 -9
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.30",
|
|
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
|
@@ -308,6 +308,14 @@ export default function register(api) {
|
|
|
308
308
|
|
|
309
309
|
logger.info(`[pier-connector][${this.accountId}] \u{1F4AC} Chat: [${jobId}] ${msgPayload.sender_id}: "${truncate(content, 40)}"`);
|
|
310
310
|
if (msgPayload.id) processedMessages.add(msgPayload.id);
|
|
311
|
+
|
|
312
|
+
// Only the assigned robot should process chat messages
|
|
313
|
+
const jobMeta = this.activeNodeJobs.get(jobId);
|
|
314
|
+
if (!jobMeta || !jobMeta.isTargeted) {
|
|
315
|
+
msg.ack();
|
|
316
|
+
continue;
|
|
317
|
+
}
|
|
318
|
+
|
|
311
319
|
msg.ack();
|
|
312
320
|
|
|
313
321
|
await this.receiveIncoming({
|
|
@@ -338,7 +346,7 @@ export default function register(api) {
|
|
|
338
346
|
if (jobId) {
|
|
339
347
|
logger.info(`[pier-connector][${this.accountId}] ⏰ Received wakeup signal for job ${jobId}`);
|
|
340
348
|
if (!this.jobSubscriptions.has(jobId)) {
|
|
341
|
-
this.activeNodeJobs.set(jobId, { pierJobId: jobId });
|
|
349
|
+
this.activeNodeJobs.set(jobId, { pierJobId: jobId, isTargeted: true });
|
|
342
350
|
await this.subscribeToJobMessages(jobId);
|
|
343
351
|
}
|
|
344
352
|
msg.ack();
|
|
@@ -408,15 +416,17 @@ export default function register(api) {
|
|
|
408
416
|
let finalText = job.task;
|
|
409
417
|
if (!isTargeted) {
|
|
410
418
|
finalText = `【PIER MARKETPLACE OPEN JOB】\nJob ID: ${job.id}\nTask: ${job.task}\n\n=== CRITICAL ===\nYou MUST use \`pier_bid_task\` to bid. Do not solve directly.`;
|
|
419
|
+
} else {
|
|
420
|
+
// Only subscribe to chat for targeted/assigned jobs
|
|
421
|
+
await this.subscribeToJobMessages(job.id);
|
|
411
422
|
}
|
|
412
423
|
|
|
413
|
-
await this.subscribeToJobMessages(job.id);
|
|
414
424
|
await this.receiveIncoming({
|
|
415
425
|
accountId: this.accountId,
|
|
416
426
|
senderId: `pier:${senderCore}`,
|
|
417
427
|
text: finalText,
|
|
418
428
|
}, job.id);
|
|
419
|
-
|
|
429
|
+
|
|
420
430
|
this.isBusy = false;
|
|
421
431
|
}
|
|
422
432
|
|
|
@@ -591,12 +601,15 @@ export default function register(api) {
|
|
|
591
601
|
try {
|
|
592
602
|
const replySubject = `chat.${jobId}`;
|
|
593
603
|
|
|
594
|
-
//
|
|
595
|
-
if (metadata?.isTargeted) {
|
|
604
|
+
// Only publish replies for jobs assigned to this robot
|
|
605
|
+
if (!metadata?.isTargeted) {
|
|
606
|
+
logger.debug(`[pier-connector][${accountId}] 🫨 Suppressing reply for non-assigned job ${jobId}`);
|
|
607
|
+
} else {
|
|
596
608
|
const chatPayload = {
|
|
597
609
|
id: crypto.randomUUID ? crypto.randomUUID() : (Math.random().toString(36).substring(2)),
|
|
598
610
|
job_id: jobId,
|
|
599
611
|
sender_id: robot.config.nodeId || 'anonymous',
|
|
612
|
+
sender_name: accountId,
|
|
600
613
|
sender_type: 'node',
|
|
601
614
|
content: text,
|
|
602
615
|
created_at: new Date().toISOString(),
|
|
@@ -605,8 +618,6 @@ export default function register(api) {
|
|
|
605
618
|
|
|
606
619
|
await robot.js.publish(replySubject, new TextEncoder().encode(JSON.stringify(chatPayload)));
|
|
607
620
|
logger.info(`[pier-connector][${accountId}] 💬 Agent reply published to NATS for job ${jobId} (Subject: ${replySubject})`);
|
|
608
|
-
} else {
|
|
609
|
-
logger.debug(`[pier-connector][${accountId}] 🤫 Pre-hiring radio silence for job ${jobId}`);
|
|
610
621
|
}
|
|
611
622
|
} catch (err) {
|
|
612
623
|
logger.error(`[pier-connector][${accountId}] Failed to publish reply: ${err.message}`);
|
|
@@ -742,8 +753,9 @@ export default function register(api) {
|
|
|
742
753
|
},
|
|
743
754
|
required: ['jobId', 'text']
|
|
744
755
|
},
|
|
745
|
-
async execute(_id, params) {
|
|
756
|
+
async execute(_id, params, ctx) {
|
|
746
757
|
const accountId = params.accountId || 'default';
|
|
758
|
+
logger.info(`[pier-connector] 🛠️ Tool called: pier_chat | jobId=${params.jobId} | accountId=${accountId}`);
|
|
747
759
|
const robot = instances.get(accountId) || instances.values().next().value;
|
|
748
760
|
if (!robot || robot.connectionStatus !== 'connected') {
|
|
749
761
|
return { content: [{ type: 'text', text: 'Error: Robot not connected' }] };
|
|
@@ -751,10 +763,20 @@ export default function register(api) {
|
|
|
751
763
|
|
|
752
764
|
try {
|
|
753
765
|
const subject = `chat.${params.jobId}`;
|
|
766
|
+
let metadata = robot.activeNodeJobs.get(params.jobId);
|
|
767
|
+
|
|
768
|
+
if (!metadata && ctx.to) {
|
|
769
|
+
const toId = ctx.to.replace(/^pier:/, '');
|
|
770
|
+
metadata = robot.activeNodeJobs.get(toId);
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
const jobId = metadata?.pierJobId || params.jobId;
|
|
774
|
+
|
|
754
775
|
const payload = {
|
|
755
776
|
id: crypto.randomUUID ? crypto.randomUUID() : (Math.random().toString(36).substring(2)),
|
|
756
|
-
job_id:
|
|
777
|
+
job_id: jobId,
|
|
757
778
|
sender_id: robot.config.nodeId,
|
|
779
|
+
sender_name: accountId,
|
|
758
780
|
sender_type: 'node',
|
|
759
781
|
content: params.text,
|
|
760
782
|
created_at: new Date().toISOString(),
|