@gholl-studio/pier-connector 0.1.5 → 0.1.6
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 +37 -3
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.
|
|
4
|
+
"version": "0.1.6",
|
|
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
|
@@ -295,11 +295,13 @@ export default function register(api) {
|
|
|
295
295
|
try {
|
|
296
296
|
const config = getActiveConfig();
|
|
297
297
|
const replySubject = `jobs.job.${jobId}.msg`;
|
|
298
|
-
|
|
298
|
+
const replyPayload = {
|
|
299
|
+
id: ethers.hexlify(ethers.randomBytes(16)), // Unique ID for frontend tracking
|
|
299
300
|
sender_id: config.nodeId,
|
|
300
301
|
content: text,
|
|
301
302
|
created_at: new Date().toISOString()
|
|
302
|
-
}
|
|
303
|
+
};
|
|
304
|
+
await js.publish(replySubject, new TextEncoder().encode(JSON.stringify(replyPayload)));
|
|
303
305
|
logger.info(`[pier-connector] 💬 Published agent reply to realtime chat for job ${jobId}`);
|
|
304
306
|
} catch (err) {
|
|
305
307
|
logger.error(`[pier-connector] Failed to send realtime reply: ${err.message}`);
|
|
@@ -554,6 +556,32 @@ export default function register(api) {
|
|
|
554
556
|
jobSubscriptions.set(jobId, iter);
|
|
555
557
|
|
|
556
558
|
(async () => {
|
|
559
|
+
let historyBuffer = [];
|
|
560
|
+
let isBursting = true;
|
|
561
|
+
|
|
562
|
+
// Small delay to collect initial "DeliverPolicy.All" burst
|
|
563
|
+
const burstTimeout = setTimeout(() => {
|
|
564
|
+
if (isBursting && historyBuffer.length > 0) {
|
|
565
|
+
isBursting = false;
|
|
566
|
+
logger.info(`[pier-connector] 📦 Batch processing ${historyBuffer.length} historical messages for ${jobId}`);
|
|
567
|
+
|
|
568
|
+
const combinedHistory = historyBuffer.map(m => `User: ${m.content}`).join('\n');
|
|
569
|
+
const lastSenderId = historyBuffer[historyBuffer.length - 1].sender_id;
|
|
570
|
+
|
|
571
|
+
receiveIncoming({
|
|
572
|
+
accountId: config.accountId || 'default',
|
|
573
|
+
senderId: `pier:${lastSenderId}`,
|
|
574
|
+
text: `[Conversation History]\n${combinedHistory}\n\nPlease continue based on the above history.`,
|
|
575
|
+
}, jobId).catch(err => {
|
|
576
|
+
logger.error(`[pier-connector] Failed to process batch history: ${err.message}`);
|
|
577
|
+
});
|
|
578
|
+
|
|
579
|
+
historyBuffer = [];
|
|
580
|
+
} else {
|
|
581
|
+
isBursting = false;
|
|
582
|
+
}
|
|
583
|
+
}, 1000); // 1s burst window
|
|
584
|
+
|
|
557
585
|
for await (const msg of iter) {
|
|
558
586
|
try {
|
|
559
587
|
const rawMsg = new TextDecoder().decode(msg.data);
|
|
@@ -592,8 +620,14 @@ export default function register(api) {
|
|
|
592
620
|
}
|
|
593
621
|
|
|
594
622
|
const content = msgPayload.content;
|
|
623
|
+
|
|
624
|
+
if (isBursting) {
|
|
625
|
+
historyBuffer.push(msgPayload);
|
|
626
|
+
msg.ack();
|
|
627
|
+
continue;
|
|
628
|
+
}
|
|
629
|
+
|
|
595
630
|
logger.info(`[pier-connector] 💬 Message for job ${jobId}: "${truncate(content, 40)}"`);
|
|
596
|
-
|
|
597
631
|
const senderCore = msgPayload.sender_id;
|
|
598
632
|
|
|
599
633
|
activeNodeJobs.set(jobId, {
|