@gholl-studio/pier-connector 0.3.24 → 0.3.26

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gholl-studio/pier-connector",
3
3
  "author": "gholl",
4
- "version": "0.3.24",
4
+ "version": "0.3.26",
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.ts",
package/src/inbound.ts CHANGED
@@ -90,8 +90,8 @@ export async function handleInbound(
90
90
  WasMentioned: true,
91
91
  CommandAuthorized: true,
92
92
  SystemPrompt: injectedPrompt,
93
- MessageId: jobId,
94
- MessageSid: jobId,
93
+ MessageId: inbound.messageId,
94
+ MessageSid: inbound.messageId,
95
95
  Metadata: {
96
96
  ...metadata,
97
97
  accountId: robot.accountId,
package/src/robot.ts CHANGED
@@ -4,8 +4,8 @@
4
4
  */
5
5
 
6
6
  import { PierClient, protocol } from '@gholl-studio/pier-sdk';
7
- const { createRequestPayload, createResultPayload, createErrorPayload } = protocol;
8
- import { parseJob, safeRespond, truncate } from './job-handler.js';
7
+ const { createRequestPayload, createResultPayload, createErrorPayload, normalizeInboundPayload } = protocol;
8
+ import { safeRespond, truncate } from './job-handler.js';
9
9
  import { jetstream, jetstreamManager, AckPolicy, DeliverPolicy, type JetStreamClient, type JetStreamManager } from '@nats-io/jetstream';
10
10
  import type { PierAccountConfig, PierPluginApi, InboundMessage } from './types.js';
11
11
 
@@ -141,7 +141,9 @@ export class PierRobot {
141
141
  accountId: this.accountId,
142
142
  senderId: `pier:${msgPayload.sender_id}`,
143
143
  body: content,
144
- jobId: jobId
144
+ jobId: jobId,
145
+ // 必须使用每条消息的唯一 ID,否则 SDK 会把同一 job 的后续消息当重复消息丢弃
146
+ messageId: msgPayload.id || `${jobId}-${Date.now()}`
145
147
  };
146
148
  this.logger.info(`[pier-connector:trace] NATS Chat Message received on PierRobot instance accountId='${this.accountId}'. Passing to handleInbound...`);
147
149
  await this.onInbound(inbound, jobId);
@@ -202,17 +204,13 @@ export class PierRobot {
202
204
  msg.ack();
203
205
 
204
206
  this.stats.received++;
205
- const parsed = parseJob(msg, this.logger);
207
+ // payload 已在上方 JSON.parse 完成,直接用 normalizeInboundPayload 转换
208
+ // 不能再调用 parseJob(msg),因为 msg 已 ack,且 JetStream consume msg 可能没有 string() 方法
209
+ const parsed = normalizeInboundPayload(payload);
206
210
  if (!parsed.ok) {
207
211
  this.stats.failed++;
208
212
  this.isBusy = false;
209
- safeRespond(msg, createErrorPayload({
210
- id: jobIdToClaim || 'unknown',
211
- errorCode: 'PARSE_ERROR',
212
- errorMessage: parsed.error,
213
- workerId: this.config.nodeId,
214
- walletAddress: this.config.walletAddress,
215
- }));
213
+ this.logger.error(`[pier-connector][${this.accountId}] ✖ Failed to parse job payload: ${parsed.error}`);
216
214
  return;
217
215
  }
218
216
 
@@ -238,7 +236,8 @@ export class PierRobot {
238
236
  accountId: this.accountId,
239
237
  senderId: `pier:${senderCore}`,
240
238
  body: finalText,
241
- jobId: job.id
239
+ jobId: job.id,
240
+ messageId: job.id // 初始任务消息用 job.id 作为唯一 ID
242
241
  }, job.id);
243
242
 
244
243
  this.isBusy = false;
package/src/types.ts CHANGED
@@ -32,6 +32,8 @@ export interface InboundMessage {
32
32
  senderId: string;
33
33
  body: string;
34
34
  jobId: string;
35
+ /** 每条 NATS 消息的唯一 ID(msgPayload.id),用于 SDK 去重,必须每条消息不同 */
36
+ messageId: string;
35
37
  }
36
38
 
37
39
  export type PierPluginApi = OpenClawPluginApi;