@gholl-studio/pier-connector 0.1.4 → 0.1.5

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 +31 -6
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",
4
+ "version": "0.1.5",
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
@@ -165,6 +165,21 @@ export default function register(api) {
165
165
  CommandAuthorized: true
166
166
  });
167
167
 
168
+ // Create a dispatcher to handle the reply lifecycle (fixes sendFinalReply error)
169
+ const { dispatcher, markDispatchIdle } = api.runtime.channel.reply.createReplyDispatcherWithTyping({
170
+ cfg: api.config,
171
+ agentId: route.agentId,
172
+ onIdle: () => {
173
+ logger.debug(`[pier-connector] Dispatcher idle for session ${route.sessionKey}`);
174
+ },
175
+ deliver: async (payload) => {
176
+ // This triggers the outbound.sendText handler we defined in pierChannel
177
+ await api.runtime.channel.reply.withReplyDispatcher(dispatcher, async () => {
178
+ // withReplyDispatcher is sometimes needed by internal SDK methods
179
+ });
180
+ }
181
+ });
182
+
168
183
  // Record session meta
169
184
  if (api.runtime.channel.session?.recordSessionMetaFromInbound) {
170
185
  try {
@@ -179,11 +194,16 @@ export default function register(api) {
179
194
  }
180
195
  }
181
196
 
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
- });
197
+ try {
198
+ // Dispatch reply — this will trigger outbound: sendText in pierChannel
199
+ await api.runtime.channel.reply.dispatchReplyFromConfig({
200
+ ctx: ctxPayload,
201
+ cfg: api.config,
202
+ dispatcher
203
+ });
204
+ } finally {
205
+ markDispatchIdle();
206
+ }
187
207
  }
188
208
 
189
209
  // ── 1. Register messaging channel ──────────────────────────────────
@@ -518,10 +538,15 @@ export default function register(api) {
518
538
  const streamName = 'PIER_JOBS';
519
539
 
520
540
  try {
541
+ // Use a unique durable name per node and job to avoid replaying acknowledged messages
542
+ const durableName = `pier_chat_${config.nodeId.replace(/[^a-zA-Z0-9]/g, '_')}_${jobId.replace(/[^a-zA-Z0-9]/g, '_')}`;
543
+
521
544
  const cInfo = await jsm.consumers.add(streamName, {
545
+ durable_name: durableName,
522
546
  filter_subject: msgSubject,
523
547
  deliver_policy: DeliverPolicy.All,
524
- ack_policy: AckPolicy.Explicit
548
+ ack_policy: AckPolicy.Explicit,
549
+ ack_wait: 30000, // 30s ack wait
525
550
  });
526
551
  const consumer = await js.consumers.get(streamName, cInfo.name);
527
552