@gholl-studio/pier-connector 0.1.2 → 0.1.3

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 +68 -18
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.2",
4
+ "version": "0.1.3",
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
@@ -127,6 +127,65 @@ export default function register(api) {
127
127
  }
128
128
  }
129
129
 
130
+ /**
131
+ * Routes an incoming message from Pier to the OpenClaw agent.
132
+ * Replaces the non-existent api.runtime.sendIncoming.
133
+ */
134
+ async function receiveIncoming(inbound, jobId) {
135
+ if (!api.runtime?.channel?.reply) {
136
+ logger.error(`[pier-connector] SDK Error: api.runtime.channel.reply is not available.`);
137
+ return;
138
+ }
139
+
140
+ const route = api.runtime.channel.routing.resolveAgentRoute({
141
+ cfg: api.config,
142
+ channel: 'pier',
143
+ accountId: inbound.accountId,
144
+ peer: {
145
+ kind: 'direct',
146
+ id: jobId
147
+ }
148
+ });
149
+
150
+ const ctxPayload = api.runtime.channel.reply.finalizeInboundContext({
151
+ Body: inbound.text,
152
+ BodyForAgent: inbound.text,
153
+ RawBody: inbound.text,
154
+ From: inbound.senderId,
155
+ To: `pier:${jobId}`,
156
+ SessionKey: route.sessionKey,
157
+ AccountId: route.accountId,
158
+ ChatType: 'direct',
159
+ SenderId: inbound.senderId,
160
+ Provider: 'pier',
161
+ Surface: 'pier',
162
+ OriginatingChannel: 'pier',
163
+ OriginatingTo: `pier:${jobId}`,
164
+ WasMentioned: true,
165
+ CommandAuthorized: true
166
+ });
167
+
168
+ // Record session meta
169
+ if (api.runtime.channel.session?.recordSessionMetaFromInbound) {
170
+ try {
171
+ const storePath = api.runtime.channel.session.resolveStorePath(api.config, route.sessionKey);
172
+ await api.runtime.channel.session.recordSessionMetaFromInbound({
173
+ storePath,
174
+ sessionKey: route.sessionKey,
175
+ ctx: ctxPayload
176
+ });
177
+ } catch (err) {
178
+ logger.debug(`[pier-connector] Failed to record session meta: ${err.message}`);
179
+ }
180
+ }
181
+
182
+ // Dispatch reply — this will trigger outbound: sendText in pierChannel
183
+ await api.runtime.channel.reply.dispatchReplyFromConfig({
184
+ ctx: ctxPayload,
185
+ cfg: api.config,
186
+ });
187
+ }
188
+
130
189
  // ── 1. Register messaging channel ──────────────────────────────────
131
190
 
132
191
  const pierChannel = {
@@ -500,17 +559,16 @@ export default function register(api) {
500
559
 
501
560
  const senderCore = msgPayload.sender_id;
502
561
 
503
- activeNodeJobs.set(senderCore, {
562
+ activeNodeJobs.set(jobId, {
504
563
  pierJobId: jobId,
505
564
  isRealtimeMsg: true
506
565
  });
507
566
 
508
- await api.runtime.sendIncoming({
509
- channelId: 'pier',
567
+ await receiveIncoming({
510
568
  accountId: config.accountId || 'default',
511
569
  senderId: `pier:${senderCore}`,
512
570
  text: content,
513
- });
571
+ }, jobId);
514
572
  }
515
573
  } catch (err) {
516
574
  logger.error(`[pier-connector] Job JS message error for ${jobId}: ${err.message}`);
@@ -567,32 +625,24 @@ export default function register(api) {
567
625
  try {
568
626
  const senderCore = job.meta?.sender ?? 'anonymous';
569
627
 
570
- activeNodeJobs.set(senderCore, {
628
+ activeNodeJobs.set(job.id, {
571
629
  pierJobId: job.id,
572
630
  pierNatsMsg: msg,
573
- pierStartTime: startTime,
631
+ pierStartTime: performance.now(),
574
632
  pierMeta: job.meta,
575
633
  isRealtimeMsg: false
576
634
  });
577
635
 
578
636
  const inbound = {
579
- channelId: 'pier',
580
637
  accountId: config.accountId || 'default',
581
638
  senderId: `pier:${senderCore}`,
582
639
  text: job.task,
583
- assignedAgentId: config.agentId || undefined,
584
640
  };
585
641
 
586
- if (job.systemPrompt) inbound.systemPrompt = job.systemPrompt;
587
-
588
- if (api.runtime?.sendIncoming) {
589
- await api.runtime.sendIncoming(inbound);
590
-
591
- // SUBSCRIBE to job-specific messages for real-time communication
592
- subscribeToJobMessages(job.id);
593
- } else {
594
- throw new Error('Agent runtime not available');
595
- }
642
+ await receiveIncoming(inbound, job.id);
643
+
644
+ // SUBSCRIBE to job-specific messages for real-time communication
645
+ subscribeToJobMessages(job.id);
596
646
  } catch (err) {
597
647
  jobsFailed++;
598
648
  safeRespond(msg, createErrorPayload({