@gholl-studio/pier-connector 0.3.20 → 0.3.21
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 +36 -11
- package/src/robot.ts +13 -1
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.21",
|
|
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
|
@@ -141,51 +141,76 @@ const pierPlugin: ChannelPlugin<PierAccountConfig> = {
|
|
|
141
141
|
}
|
|
142
142
|
},
|
|
143
143
|
|
|
144
|
+
// -------------------------------------------------------------------------
|
|
145
|
+
// Status Adapter
|
|
146
|
+
// -------------------------------------------------------------------------
|
|
147
|
+
status: {
|
|
148
|
+
buildAccountSnapshot: ({ account, cfg }) => {
|
|
149
|
+
const robot = instances.get(account.accountId);
|
|
150
|
+
return {
|
|
151
|
+
accountId: account.accountId,
|
|
152
|
+
running: !!robot,
|
|
153
|
+
connected: robot?.connectionStatus === 'connected',
|
|
154
|
+
lastStartAt: (robot as any)?.lastStartAt,
|
|
155
|
+
lastStopAt: (robot as any)?.lastStopAt,
|
|
156
|
+
lastError: (robot as any)?.lastError,
|
|
157
|
+
healthState: robot?.connectionStatus === 'connected' ? 'healthy' : 'degraded',
|
|
158
|
+
};
|
|
159
|
+
},
|
|
160
|
+
resolveAccountState: ({ configured, enabled }) => {
|
|
161
|
+
return configured && enabled ? 'enabled' : 'disabled';
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
|
|
144
165
|
// -------------------------------------------------------------------------
|
|
145
166
|
// Gateway Adapter
|
|
146
167
|
// -------------------------------------------------------------------------
|
|
147
168
|
gateway: {
|
|
148
169
|
startAccount: async (ctx) => {
|
|
149
170
|
const config = ctx.account;
|
|
150
|
-
|
|
151
|
-
|
|
171
|
+
// ctx has .log, .runtime, .cfg, etc.
|
|
172
|
+
const robot = new PierRobot(config, ctx as any, async (inbound, jobId) => {
|
|
152
173
|
await handleInbound(ctx.runtime, inbound, jobId, robot, pierPlugin);
|
|
153
174
|
});
|
|
154
175
|
instances.set(ctx.accountId, robot);
|
|
155
176
|
|
|
156
177
|
try {
|
|
178
|
+
(robot as any).lastStartAt = Date.now();
|
|
157
179
|
await robot.start();
|
|
180
|
+
|
|
158
181
|
ctx.setStatus({
|
|
159
182
|
...ctx.getStatus(),
|
|
160
183
|
running: true,
|
|
161
|
-
|
|
184
|
+
connected: true,
|
|
185
|
+
lastStartAt: (robot as any).lastStartAt
|
|
162
186
|
} as any);
|
|
163
187
|
|
|
164
|
-
//
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
});
|
|
188
|
+
// Note: We resolve here to signal successful startup.
|
|
189
|
+
// The robot stays alive in the 'instances' map.
|
|
190
|
+
// If OpenClaw requires a long-running promise, we can revert to keeping it alive,
|
|
191
|
+
// but usually, status monitoring is enough for non-standard services.
|
|
192
|
+
console.log(`[pier-connector][${ctx.accountId}] Startup successful and resolved.`);
|
|
170
193
|
} catch (err: any) {
|
|
194
|
+
(robot as any).lastError = err.message;
|
|
171
195
|
ctx.setStatus({
|
|
172
196
|
...ctx.getStatus(),
|
|
173
197
|
running: false,
|
|
174
198
|
lastError: err.message
|
|
175
199
|
} as any);
|
|
176
|
-
throw err;
|
|
200
|
+
throw err;
|
|
177
201
|
}
|
|
178
202
|
},
|
|
179
203
|
stopAccount: async (ctx) => {
|
|
180
204
|
const robot = instances.get(ctx.accountId);
|
|
181
205
|
if (robot) {
|
|
206
|
+
(robot as any).lastStopAt = Date.now();
|
|
182
207
|
await robot.stop();
|
|
183
208
|
instances.delete(ctx.accountId);
|
|
184
209
|
}
|
|
185
210
|
ctx.setStatus({
|
|
186
211
|
...ctx.getStatus(),
|
|
187
212
|
running: false,
|
|
188
|
-
lastStopAt:
|
|
213
|
+
lastStopAt: (robot as any).lastStopAt
|
|
189
214
|
} as any);
|
|
190
215
|
}
|
|
191
216
|
}
|
package/src/robot.ts
CHANGED
|
@@ -38,8 +38,20 @@ export class PierRobot {
|
|
|
38
38
|
this.config = config;
|
|
39
39
|
this.accountId = config.accountId;
|
|
40
40
|
this.runtime = runtime;
|
|
41
|
-
this.logger = runtime.log || console;
|
|
42
41
|
this.onInbound = onInbound;
|
|
42
|
+
|
|
43
|
+
// Robust logger wrapper
|
|
44
|
+
if (runtime.log && typeof runtime.log === 'object' && 'error' in runtime.log) {
|
|
45
|
+
this.logger = runtime.log;
|
|
46
|
+
} else {
|
|
47
|
+
this.logger = {
|
|
48
|
+
info: (msg: string) => (typeof runtime.log === 'function' ? runtime.log(msg) : console.log(msg)),
|
|
49
|
+
error: (msg: string) => (typeof runtime.error === 'function' ? runtime.error(msg) : console.error(msg)),
|
|
50
|
+
warn: (msg: string) => (typeof runtime.warn === 'function' ? runtime.warn(msg) : console.warn(msg)),
|
|
51
|
+
debug: (msg: string) => (typeof runtime.debug === 'function' ? runtime.debug(msg) : console.debug ? console.debug(msg) : console.log(msg)),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
43
55
|
this.client = new PierClient({
|
|
44
56
|
apiUrl: config.pierApiUrl,
|
|
45
57
|
natsUrl: config.natsUrl,
|