@gholl-studio/pier-connector 0.2.29 → 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 +35 -16
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
|
@@ -416,15 +416,17 @@ export default function register(api) {
|
|
|
416
416
|
let finalText = job.task;
|
|
417
417
|
if (!isTargeted) {
|
|
418
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);
|
|
419
422
|
}
|
|
420
423
|
|
|
421
|
-
await this.subscribeToJobMessages(job.id);
|
|
422
424
|
await this.receiveIncoming({
|
|
423
425
|
accountId: this.accountId,
|
|
424
426
|
senderId: `pier:${senderCore}`,
|
|
425
427
|
text: finalText,
|
|
426
428
|
}, job.id);
|
|
427
|
-
|
|
429
|
+
|
|
428
430
|
this.isBusy = false;
|
|
429
431
|
}
|
|
430
432
|
|
|
@@ -599,18 +601,24 @@ export default function register(api) {
|
|
|
599
601
|
try {
|
|
600
602
|
const replySubject = `chat.${jobId}`;
|
|
601
603
|
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
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 {
|
|
608
|
+
const chatPayload = {
|
|
609
|
+
id: crypto.randomUUID ? crypto.randomUUID() : (Math.random().toString(36).substring(2)),
|
|
610
|
+
job_id: jobId,
|
|
611
|
+
sender_id: robot.config.nodeId || 'anonymous',
|
|
612
|
+
sender_name: accountId,
|
|
613
|
+
sender_type: 'node',
|
|
614
|
+
content: text,
|
|
615
|
+
created_at: new Date().toISOString(),
|
|
616
|
+
auth_token: robot.config.secretKey
|
|
617
|
+
};
|
|
618
|
+
|
|
619
|
+
await robot.js.publish(replySubject, new TextEncoder().encode(JSON.stringify(chatPayload)));
|
|
620
|
+
logger.info(`[pier-connector][${accountId}] 💬 Agent reply published to NATS for job ${jobId} (Subject: ${replySubject})`);
|
|
621
|
+
}
|
|
614
622
|
} catch (err) {
|
|
615
623
|
logger.error(`[pier-connector][${accountId}] Failed to publish reply: ${err.message}`);
|
|
616
624
|
}
|
|
@@ -745,8 +753,9 @@ export default function register(api) {
|
|
|
745
753
|
},
|
|
746
754
|
required: ['jobId', 'text']
|
|
747
755
|
},
|
|
748
|
-
async execute(_id, params) {
|
|
756
|
+
async execute(_id, params, ctx) {
|
|
749
757
|
const accountId = params.accountId || 'default';
|
|
758
|
+
logger.info(`[pier-connector] 🛠️ Tool called: pier_chat | jobId=${params.jobId} | accountId=${accountId}`);
|
|
750
759
|
const robot = instances.get(accountId) || instances.values().next().value;
|
|
751
760
|
if (!robot || robot.connectionStatus !== 'connected') {
|
|
752
761
|
return { content: [{ type: 'text', text: 'Error: Robot not connected' }] };
|
|
@@ -754,10 +763,20 @@ export default function register(api) {
|
|
|
754
763
|
|
|
755
764
|
try {
|
|
756
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
|
+
|
|
757
775
|
const payload = {
|
|
758
776
|
id: crypto.randomUUID ? crypto.randomUUID() : (Math.random().toString(36).substring(2)),
|
|
759
|
-
job_id:
|
|
777
|
+
job_id: jobId,
|
|
760
778
|
sender_id: robot.config.nodeId,
|
|
779
|
+
sender_name: accountId,
|
|
761
780
|
sender_type: 'node',
|
|
762
781
|
content: params.text,
|
|
763
782
|
created_at: new Date().toISOString(),
|