@gholl-studio/pier-connector 0.2.36 → 0.2.37

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 +26 -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.2.36",
4
+ "version": "0.2.37",
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
@@ -168,8 +168,32 @@ export default function register(api) {
168
168
  peer: { kind: 'direct', id: jobId }
169
169
  });
170
170
 
171
- const finalAgentId = this.config.agentId || route.agentId;
172
- logger.info(`[pier-connector] Routing account '${inbound.accountId}' -> agent '${finalAgentId}' (Source: ${this.config.agentId ? 'account-config' : (route.agentId ? 'global-bindings' : 'default-routing')})`);
171
+ // Smart Fallback Strategy:
172
+ // 1. Explicit account-level agentId
173
+ // 2. Global bindings from openclaw.json
174
+ // 3. Exact name match (account ID == agent ID)
175
+ // 4. Default routing
176
+ let finalAgentId = this.config.agentId;
177
+ let routingSource = 'account-config';
178
+
179
+ if (!finalAgentId && route.agentId && route.agentId !== 'main' && route.agentId !== 'default') {
180
+ finalAgentId = route.agentId;
181
+ routingSource = 'global-bindings';
182
+ }
183
+
184
+ if (!finalAgentId) {
185
+ // Check if accountId matches an existing agent slug/ID
186
+ const agents = (api.runtime && typeof api.runtime.getAgents === 'function') ? await api.runtime.getAgents() : {};
187
+ if (agents && agents[inbound.accountId]) {
188
+ finalAgentId = inbound.accountId;
189
+ routingSource = 'name-match-fallback';
190
+ } else {
191
+ finalAgentId = route.agentId || 'main'; // Ultimate fallback
192
+ routingSource = route.agentId ? 'global-bindings-fallback' : 'default-routing';
193
+ }
194
+ }
195
+
196
+ logger.info(`[pier-connector] Routing account '${inbound.accountId}' -> agent '${finalAgentId}' (Source: ${routingSource})`);
173
197
 
174
198
  const dynamicSessionKey = `pier-job-${jobId}`;
175
199
  const metadata = this.activeNodeJobs.get(jobId);