@gholl-studio/pier-connector 0.3.19 → 0.3.20
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.ts +26 -9
- package/src/robot.ts +10 -2
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.
|
|
4
|
+
"version": "0.3.20",
|
|
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/index.ts
CHANGED
|
@@ -147,17 +147,34 @@ const pierPlugin: ChannelPlugin<PierAccountConfig> = {
|
|
|
147
147
|
gateway: {
|
|
148
148
|
startAccount: async (ctx) => {
|
|
149
149
|
const config = ctx.account;
|
|
150
|
-
const robot = new PierRobot(config,
|
|
150
|
+
const robot = new PierRobot(config, ctx.runtime, async (inbound, jobId) => {
|
|
151
151
|
// Pass the context-aware runtime and the plugin instance
|
|
152
|
-
await handleInbound(
|
|
152
|
+
await handleInbound(ctx.runtime, inbound, jobId, robot, pierPlugin);
|
|
153
153
|
});
|
|
154
154
|
instances.set(ctx.accountId, robot);
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
155
|
+
|
|
156
|
+
try {
|
|
157
|
+
await robot.start();
|
|
158
|
+
ctx.setStatus({
|
|
159
|
+
...ctx.getStatus(),
|
|
160
|
+
running: true,
|
|
161
|
+
lastStartAt: Date.now()
|
|
162
|
+
} as any);
|
|
163
|
+
|
|
164
|
+
// Keep the account active until the abort signal is received
|
|
165
|
+
await new Promise<void>((resolve) => {
|
|
166
|
+
ctx.abortSignal.addEventListener('abort', () => {
|
|
167
|
+
resolve();
|
|
168
|
+
}, { once: true });
|
|
169
|
+
});
|
|
170
|
+
} catch (err: any) {
|
|
171
|
+
ctx.setStatus({
|
|
172
|
+
...ctx.getStatus(),
|
|
173
|
+
running: false,
|
|
174
|
+
lastError: err.message
|
|
175
|
+
} as any);
|
|
176
|
+
throw err; // Re-throw to signal failure to Gateway
|
|
177
|
+
}
|
|
161
178
|
},
|
|
162
179
|
stopAccount: async (ctx) => {
|
|
163
180
|
const robot = instances.get(ctx.accountId);
|
|
@@ -168,7 +185,7 @@ const pierPlugin: ChannelPlugin<PierAccountConfig> = {
|
|
|
168
185
|
ctx.setStatus({
|
|
169
186
|
...ctx.getStatus(),
|
|
170
187
|
running: false,
|
|
171
|
-
lastStopAt:
|
|
188
|
+
lastStopAt: Date.now()
|
|
172
189
|
} as any);
|
|
173
190
|
}
|
|
174
191
|
}
|
package/src/robot.ts
CHANGED
|
@@ -292,16 +292,24 @@ export class PierRobot {
|
|
|
292
292
|
await this.setupMarketplaceConsumer(streamName, this.config.subject, durableNameMarket);
|
|
293
293
|
await this.setupMarketplaceConsumer(streamName, `jobs.node.${this.config.nodeId}`, durableNameDirect);
|
|
294
294
|
|
|
295
|
+
if (this.heartbeatTimer) clearInterval(this.heartbeatTimer);
|
|
295
296
|
this.heartbeatTimer = setInterval(() => this.heartbeat(), 60000);
|
|
296
297
|
} catch (err: any) {
|
|
297
298
|
this.connectionStatus = 'error';
|
|
298
299
|
this.logger.error(`[pier-connector][${this.accountId}] Start failed: ${err.message}`);
|
|
300
|
+
throw err; // Re-throw to signal failure to Gateway
|
|
299
301
|
}
|
|
300
302
|
}
|
|
301
303
|
|
|
302
304
|
async stop() {
|
|
303
|
-
if (this.heartbeatTimer)
|
|
304
|
-
|
|
305
|
+
if (this.heartbeatTimer) {
|
|
306
|
+
clearInterval(this.heartbeatTimer);
|
|
307
|
+
this.heartbeatTimer = null;
|
|
308
|
+
}
|
|
309
|
+
if (this.nc) {
|
|
310
|
+
await this.client.drainNats();
|
|
311
|
+
this.nc = null;
|
|
312
|
+
}
|
|
305
313
|
this.connectionStatus = 'disconnected';
|
|
306
314
|
}
|
|
307
315
|
}
|