@gholl-studio/pier-connector 0.2.51 → 0.2.52

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 +5 -3
  2. package/src/index.js +29 -15
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gholl-studio/pier-connector",
3
3
  "author": "gholl",
4
- "version": "0.2.51",
4
+ "version": "0.2.52",
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",
@@ -50,6 +50,8 @@
50
50
  }
51
51
  },
52
52
  "devDependencies": {
53
- "dotenv": "^17.3.1"
53
+ "dotenv": "^17.3.1",
54
+ "openclaw": ">=2.0.0",
55
+ "typescript": "^5.0.0"
54
56
  }
55
- }
57
+ }
package/src/index.js CHANGED
@@ -8,6 +8,7 @@
8
8
  * 4. A command ("/pier") for checking connection status
9
9
  */
10
10
 
11
+ import { definePluginEntry } from 'openclaw/plugin-sdk/plugin-entry';
11
12
  import { PierClient, protocol } from '@gholl-studio/pier-sdk';
12
13
  const { createRequestPayload, createResultPayload, createErrorPayload } = protocol;
13
14
  import { parseJob, safeRespond, truncate } from './job-handler.js';
@@ -22,7 +23,7 @@ import path from 'path';
22
23
  *
23
24
  * @param {object} api – OpenClaw plugin API
24
25
  */
25
- export default function register(api) {
26
+ const register = (api) => {
26
27
  const logger = api.logger;
27
28
 
28
29
  // ── shared state (Instances) ───────────────────────────────────
@@ -38,11 +39,15 @@ export default function register(api) {
38
39
  // ── resolve plugin config ──────────────────────────────────────────
39
40
 
40
41
  function resolveConfigs() {
41
- const globalAccounts = api.runtime?.config?.channels?.['pier']?.accounts || {};
42
- const pluginAccounts = api.config?.channels?.['pier']?.accounts || {};
42
+ // api.config is the full global OpenClaw configuration
43
+ const globalAccounts = api.config?.channels?.['pier']?.accounts || {};
44
+
45
+ // api.pluginConfig is the scoped config for THIS plugin
46
+ const pluginAccounts = api.pluginConfig?.accounts || {};
47
+
43
48
  const rawAccounts = { ...globalAccounts, ...pluginAccounts };
44
49
 
45
- const legacyCfg = api.config?.plugins?.entries?.['pier-connector']?.config || api.config || {};
50
+ const legacyCfg = api.pluginConfig || {};
46
51
 
47
52
  // If no accounts defined at all, fallback to 'default' using legacy/env config
48
53
  if (Object.keys(rawAccounts).length === 0) {
@@ -168,15 +173,15 @@ export default function register(api) {
168
173
  logger.info(`[pier-connector:trace] receiveIncoming triggered for jobId=${jobId}. accountId='${inbound.accountId}', senderId='${inbound.senderId}'`);
169
174
 
170
175
  // 1. Resolve Global Configuration
171
- // In OpenClaw V2, we need the FULL config for routing to work, but api.runtime.config is often scoped to the plugin.
172
- // We search for the root config and fall back to whatever is available.
173
- const rootConfig = api.rootConfig || api.runtime?.globalConfig || api.runtime?.config || {};
176
+ // In OpenClaw V2, we use api.config for the full global state.
177
+ const rootConfig = api.config || {};
174
178
 
175
- // Diagnostic logging (only if we suspect it's still failing)
176
- const bindingsCount = Array.isArray(rootConfig.bindings) ? rootConfig.bindings.length : 0;
179
+ // Diagnostic logging
180
+ const b = rootConfig.bindings;
181
+ const bindingsCount = Array.isArray(b) ? b.length : (b ? Object.keys(b).length : 0);
177
182
  const agentsCount = rootConfig.agents?.list ? (Array.isArray(rootConfig.agents.list) ? rootConfig.agents.list.length : Object.keys(rootConfig.agents.list).length) : 0;
178
183
 
179
- logger.info(`[pier-connector:trace] Diagnostic: rootConfig source=${api.rootConfig ? 'api.rootConfig' : (api.runtime?.globalConfig ? 'globalConfig' : 'runtime.config')}, bindings=${bindingsCount}, agents=${agentsCount}`);
184
+ logger.info(`[pier-connector:trace] Diagnostic: rootConfig source=api.config, bindings=${bindingsCount}, agents=${agentsCount}`);
180
185
 
181
186
  // 2. Resolve Agent Route via SDK
182
187
  const route = api.runtime.channel.routing.resolveAgentRoute({
@@ -201,9 +206,9 @@ export default function register(api) {
201
206
  // B. Check Global Bindings (Manual Scan of rootConfig.bindings)
202
207
  if (!finalAgentId) {
203
208
  const bindings = Array.isArray(rootConfig.bindings) ? rootConfig.bindings : [];
204
- const binding = bindings.find(b =>
205
- b.match?.channel === 'pier' &&
206
- (b.match?.accountId === inbound.accountId || b.match?.account === inbound.accountId)
209
+ const binding = bindings.find(bi =>
210
+ bi.match?.channel === 'pier' &&
211
+ (bi.match?.accountId === inbound.accountId || bi.match?.account === inbound.accountId)
207
212
  );
208
213
  if (binding?.agentId && binding.agentId !== 'main') {
209
214
  finalAgentId = binding.agentId;
@@ -230,6 +235,7 @@ export default function register(api) {
230
235
  }
231
236
  }
232
237
 
238
+
233
239
  // E. Ultimate Fallback
234
240
  if (!finalAgentId) {
235
241
  finalAgentId = route.agentId || 'main'; // Use SDK result or hard default 'main'
@@ -297,7 +303,7 @@ export default function register(api) {
297
303
  });
298
304
 
299
305
  const { dispatcher, markDispatchIdle } = api.runtime.channel.reply.createReplyDispatcherWithTyping({
300
- cfg: api.runtime.config,
306
+ cfg: api.config,
301
307
  agentId: finalAgentId,
302
308
  deliver: async (payload) => {
303
309
  const currentMeta = this.activeNodeJobs.get(jobId);
@@ -324,7 +330,7 @@ export default function register(api) {
324
330
 
325
331
  try {
326
332
  await api.runtime.channel.reply.dispatchReplyFromConfig({
327
- ctx: ctxPayload, cfg: api.runtime.config, dispatcher
333
+ ctx: ctxPayload, cfg: api.config, dispatcher
328
334
  });
329
335
  } finally {
330
336
  markDispatchIdle();
@@ -1220,3 +1226,11 @@ export default function register(api) {
1220
1226
 
1221
1227
  logger.info('[pier-connector] Plugin registered');
1222
1228
  }
1229
+
1230
+ export default definePluginEntry({
1231
+ id: 'pier-connector',
1232
+ name: 'Pier Connector',
1233
+ description: 'Connects OpenClaw to the Pier job marketplace.',
1234
+ register
1235
+ });
1236
+