@gholl-studio/pier-connector 0.2.44 → 0.2.46

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 +35 -23
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.44",
4
+ "version": "0.2.46",
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
@@ -172,39 +172,51 @@ export default function register(api) {
172
172
 
173
173
  logger.info(`[pier-connector:trace] resolveAgentRoute returned: route.agentId='${route?.agentId}', route.accountId='${route?.accountId}'`);
174
174
 
175
- // Smart Fallback Strategy:
176
- // 1. Explicit account-level agentId
177
- // 2. Global bindings from openclaw.json
178
- // 3. Exact name match (account ID == agent ID)
179
- // 4. Default routing
175
+ // 1. Explicit account-level agentId from plugin config (if still used)
180
176
  let finalAgentId = this.config.agentId;
181
177
  let routingSource = 'account-config';
182
178
 
183
- if (!finalAgentId && route.agentId && route.agentId !== 'main' && route.agentId !== 'default') {
184
- finalAgentId = route.agentId;
185
- routingSource = 'global-bindings';
186
- }
179
+ // 2. Robust manual parse (safeguard against OpenClaw core parsing bugs)
180
+ if (!finalAgentId && api.runtime?.config) {
181
+ const cfg = api.runtime.config;
182
+ const bs = Array.isArray(cfg.bindings) ? cfg.bindings : [];
183
+ const al = Array.isArray(cfg.agents?.list) ? cfg.agents.list : [];
184
+
185
+ logger.info(`[pier-connector:trace] Manual debug: bindings_count=${bs.length}, agents_count=${al.length}`);
187
186
 
188
- if (!finalAgentId) {
189
- // Check if accountId matches an existing agent slug/ID
190
- const rawAgents = (api.runtime && typeof api.runtime.getAgents === 'function') ? await api.runtime.getAgents() : null;
191
- let isAgentValid = false;
187
+ // Check bindings
188
+ const manualBinding = bs.find(b =>
189
+ b.match?.channel === 'pier' &&
190
+ (b.match?.accountId === inbound.accountId || b.match?.account === inbound.accountId)
191
+ );
192
192
 
193
- if (Array.isArray(rawAgents)) {
194
- isAgentValid = !!rawAgents.find(a => a.id === inbound.accountId);
195
- } else if (rawAgents && typeof rawAgents === 'object') {
196
- isAgentValid = !!rawAgents[inbound.accountId];
193
+ if (manualBinding && manualBinding.agentId && manualBinding.agentId !== 'main') {
194
+ finalAgentId = manualBinding.agentId;
195
+ routingSource = 'manual-global-bindings';
197
196
  }
198
197
 
199
- if (isAgentValid) {
200
- finalAgentId = inbound.accountId;
201
- routingSource = 'name-match-fallback';
202
- } else {
203
- finalAgentId = route.agentId || 'main'; // Ultimate fallback
204
- routingSource = route.agentId ? 'global-bindings-fallback' : 'default-routing';
198
+ // Check agent list for name match (account ID == agent ID)
199
+ if (!finalAgentId) {
200
+ const nameMatch = al.find(a => a.id === inbound.accountId);
201
+ if (nameMatch) {
202
+ finalAgentId = inbound.accountId;
203
+ routingSource = 'manual-name-match';
204
+ }
205
205
  }
206
206
  }
207
207
 
208
+ // 3. Fallback to OpenClaw's resolveAgentRoute (only if still unresolved and not 'main')
209
+ if (!finalAgentId && route.agentId && route.agentId !== 'main' && route.agentId !== 'default') {
210
+ finalAgentId = route.agentId;
211
+ routingSource = 'sdk-global-bindings';
212
+ }
213
+
214
+ // 4. Ultimate default
215
+ if (!finalAgentId) {
216
+ finalAgentId = route.agentId || 'main'; // Ultimate fallback
217
+ routingSource = route.agentId ? 'global-bindings-fallback' : 'default-routing';
218
+ }
219
+
208
220
  logger.info(`[pier-connector] Routing account '${inbound.accountId}' -> agent '${finalAgentId}' (Source: ${routingSource})`);
209
221
 
210
222
  const dynamicSessionKey = `pier-job-${jobId}`;