@gholl-studio/pier-connector 0.1.8 → 0.2.0

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 +17 -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.8",
4
+ "version": "0.2.0",
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
@@ -306,15 +306,19 @@ export default function register(api) {
306
306
  const config = getActiveConfig();
307
307
  const replySubject = `jobs.job.${jobId}.msg`;
308
308
  const replyPayload = {
309
- id: ethers.hexlify(ethers.randomBytes(16)), // Unique ID for frontend tracking
309
+ id: ethers.hexlify(ethers.randomBytes(16)),
310
+ job_id: jobId,
310
311
  sender_id: config.nodeId,
312
+ sender_type: 'node',
311
313
  content: text,
312
- created_at: new Date().toISOString()
314
+ timestamp: new Date().toISOString(),
315
+ auth_token: config.secretKey // Secure token for backend validation
313
316
  };
317
+
314
318
  await js.publish(replySubject, new TextEncoder().encode(JSON.stringify(replyPayload)));
315
- logger.info(`[pier-connector] 💬 Published agent reply to realtime chat for job ${jobId}`);
319
+ logger.info(`[pier-connector] 💬 Agent reply published directly to NATS for job ${jobId}`);
316
320
  } catch (err) {
317
- logger.error(`[pier-connector] Failed to send realtime reply: ${err.message}`);
321
+ logger.error(`[pier-connector] Failed to publish realtime reply to NATS: ${err.message}`);
318
322
  }
319
323
  } else if (js) {
320
324
  // Publish result to jobs.submit via JetStream (not msg.respond)
@@ -925,29 +929,21 @@ export default function register(api) {
925
929
  }
926
930
 
927
931
  try {
932
+
933
+ const config = getActiveConfig();
934
+ const subject = `jobs.job.${params.jobId}.msg`;
928
935
  const payload = {
929
- sender_id: getActiveConfig().nodeId,
936
+ id: ethers.hexlify(ethers.randomBytes(16)),
937
+ job_id: params.jobId,
938
+ sender_id: config.nodeId,
939
+ sender_type: 'node',
930
940
  content: params.text,
931
- created_at: new Date().toISOString()
941
+ timestamp: new Date().toISOString(),
942
+ auth_token: config.secretKey // Secure token for backend validation
932
943
  };
933
944
 
934
- const subject = `jobs.job.${params.jobId}.msg`;
935
945
  await js.publish(subject, new TextEncoder().encode(JSON.stringify(payload)));
936
946
 
937
- // Also SAVE to database for persistence
938
- const config = getActiveConfig();
939
- await fetch(`${config.pierApiUrl}/jobs/${params.jobId}/messages`, {
940
- method: 'POST',
941
- headers: {
942
- 'Content-Type': 'application/json',
943
- 'Authorization': `Bearer ${config.secretKey}` // BUG-7: Use Authorization header, not X-API-Key
944
- },
945
- body: JSON.stringify({
946
- sender_id: config.nodeId,
947
- content: params.text
948
- })
949
- });
950
-
951
947
  return { content: [{ type: 'text', text: 'Message sent' }] };
952
948
  } catch (err) {
953
949
  return { content: [{ type: 'text', text: `Error: ${err.message}` }] };