@gholl-studio/pier-connector 0.2.17 → 0.2.18

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +27 -40
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.17",
4
+ "version": "0.2.18",
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
@@ -351,42 +351,26 @@ export default function register(api) {
351
351
  const msg = metadata?.pierNatsMsg;
352
352
  const isRealtimeMsg = metadata?.isRealtimeMsg;
353
353
 
354
- if (msg || isRealtimeMsg) {
355
- const elapsed = metadata?.pierStartTime
356
- ? (performance.now() - metadata.pierStartTime).toFixed(1)
357
- : null;
358
-
359
- const responsePayload = createResultPayload({
360
- id: jobId,
361
- reply: text,
362
- latencyMs: elapsed ? Number(elapsed) : undefined,
363
- workerId: getActiveConfig().nodeId,
364
- walletAddress: getActiveConfig().walletAddress,
365
- });
366
-
367
- if (isRealtimeMsg && js) {
368
- try {
369
- const config = getActiveConfig();
370
- const replySubject = `jobs.job.${jobId}.msg`;
371
- const replyPayload = {
372
- id: ethers.hexlify(ethers.randomBytes(16)),
373
- job_id: jobId,
374
- sender_id: config.nodeId,
375
- sender_type: 'node',
376
- content: text,
377
- timestamp: new Date().toISOString(),
378
- auth_token: config.secretKey // Secure token for backend validation
379
- };
380
-
381
- await js.publish(replySubject, new TextEncoder().encode(JSON.stringify(replyPayload)));
382
- logger.info(`[pier-connector] 💬 Agent reply published directly to NATS for job ${jobId}`);
383
- } catch (err) {
384
- logger.error(`[pier-connector] Failed to publish realtime reply to NATS: ${err.message}`);
385
- }
386
- } else if (js) {
387
- // BUG-44: Marketplace results are now buffered in receiveIncoming and submitted ONCE at the end.
388
- // sendText only logs the progress here.
389
- logger.debug(`[pier-connector] ⏳ Marketplace response buffered: "${truncate(text, 40)}"`);
354
+ if (jobId && js) { // Ensure we have a jobId and NATS JetStream is available
355
+ try {
356
+ const config = getActiveConfig();
357
+ const replySubject = `jobs.job.${jobId}.msg`;
358
+
359
+ // Treat ALL agent text outputs as Chat Messages so the Employer sees them in real-time
360
+ const chatPayload = {
361
+ id: crypto.randomUUID ? crypto.randomUUID() : (Math.random().toString(36).substring(2)),
362
+ job_id: jobId,
363
+ sender_id: config.nodeId || 'anonymous',
364
+ sender_type: 'node',
365
+ content: text,
366
+ timestamp: new Date().toISOString(),
367
+ auth_token: config.secretKey // Secure token for backend validation
368
+ };
369
+
370
+ await js.publish(replySubject, new TextEncoder().encode(JSON.stringify(chatPayload)));
371
+ logger.info(`[pier-connector] 💬 Agent reply published directly to NATS chat for job ${jobId}`);
372
+ } catch (err) {
373
+ logger.error(`[pier-connector] Failed to publish realtime reply to NATS: ${err.message}`);
390
374
  }
391
375
 
392
376
  // Delayed stop for job-specific message listener
@@ -835,10 +819,12 @@ export default function register(api) {
835
819
  return;
836
820
  }
837
821
 
838
- // For Marketplace jobs (those without assigned_node_id, or even those with it),
839
- // we must ATOMICALLY CLAIM it from the backend before setting isBusy.
822
+ // For Marketplace jobs: if assigned_node_id IS NOT present, it's open!
823
+ // Do NOT claim it, let the agent evaluate and use pier_bid_task instead.
840
824
  const jobIdToClaim = payload.id;
841
- if (jobIdToClaim) {
825
+ const isTargeted = !!(payload.assigned_node_id || payload.targetNodeId || payload.TargetNodeID);
826
+
827
+ if (jobIdToClaim && isTargeted) {
842
828
  const claimResult = await claimJob(jobIdToClaim);
843
829
  if (!claimResult.ok) {
844
830
  if (claimResult.alreadyClaimed) {
@@ -852,7 +838,8 @@ export default function register(api) {
852
838
  }
853
839
  }
854
840
 
855
- // Claimed successfully! Set busy state
841
+ // For an open bidding job, we don't lock the DB but we do set the node `isBusy` temporarily
842
+ // while it thinks whether to bid or not.
856
843
  isBusy = true;
857
844
  msg.ack();
858
845