@gholl-studio/pier-connector 0.2.50 → 0.2.51
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.js +50 -40
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.
|
|
4
|
+
"version": "0.2.51",
|
|
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
|
@@ -165,11 +165,22 @@ export default function register(api) {
|
|
|
165
165
|
return;
|
|
166
166
|
}
|
|
167
167
|
|
|
168
|
-
logger.info(`[pier-connector:trace] receiveIncoming triggered.
|
|
168
|
+
logger.info(`[pier-connector:trace] receiveIncoming triggered for jobId=${jobId}. accountId='${inbound.accountId}', senderId='${inbound.senderId}'`);
|
|
169
169
|
|
|
170
|
-
|
|
170
|
+
// 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 || {};
|
|
174
|
+
|
|
175
|
+
// Diagnostic logging (only if we suspect it's still failing)
|
|
176
|
+
const bindingsCount = Array.isArray(rootConfig.bindings) ? rootConfig.bindings.length : 0;
|
|
177
|
+
const agentsCount = rootConfig.agents?.list ? (Array.isArray(rootConfig.agents.list) ? rootConfig.agents.list.length : Object.keys(rootConfig.agents.list).length) : 0;
|
|
178
|
+
|
|
179
|
+
logger.info(`[pier-connector:trace] Diagnostic: rootConfig source=${api.rootConfig ? 'api.rootConfig' : (api.runtime?.globalConfig ? 'globalConfig' : 'runtime.config')}, bindings=${bindingsCount}, agents=${agentsCount}`);
|
|
180
|
+
|
|
181
|
+
// 2. Resolve Agent Route via SDK
|
|
171
182
|
const route = api.runtime.channel.routing.resolveAgentRoute({
|
|
172
|
-
cfg:
|
|
183
|
+
cfg: rootConfig,
|
|
173
184
|
channel: 'pier',
|
|
174
185
|
account: inbound.accountId,
|
|
175
186
|
peer: { kind: 'direct', id: jobId }
|
|
@@ -177,57 +188,54 @@ export default function register(api) {
|
|
|
177
188
|
|
|
178
189
|
logger.info(`[pier-connector:trace] resolveAgentRoute returned: route.agentId='${route?.agentId}', route.accountId='${route?.accountId}'`);
|
|
179
190
|
|
|
180
|
-
//
|
|
181
|
-
let finalAgentId =
|
|
182
|
-
let routingSource = '
|
|
191
|
+
// 3. Robust Routing Decision Tree
|
|
192
|
+
let finalAgentId = null;
|
|
193
|
+
let routingSource = 'unresolved';
|
|
183
194
|
|
|
184
|
-
//
|
|
185
|
-
if (
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
logger.info(`[pier-connector:trace] Manual debug: bindings_count=${bs.length}, agents_count=${al.length}`);
|
|
195
|
+
// A. Check explicit account-level binding in plugin local config (this.config)
|
|
196
|
+
if (this.config.agentId && this.config.agentId !== 'main' && this.config.agentId !== 'default') {
|
|
197
|
+
finalAgentId = this.config.agentId;
|
|
198
|
+
routingSource = 'plugin-local-config';
|
|
199
|
+
}
|
|
191
200
|
|
|
192
|
-
|
|
193
|
-
|
|
201
|
+
// B. Check Global Bindings (Manual Scan of rootConfig.bindings)
|
|
202
|
+
if (!finalAgentId) {
|
|
203
|
+
const bindings = Array.isArray(rootConfig.bindings) ? rootConfig.bindings : [];
|
|
204
|
+
const binding = bindings.find(b =>
|
|
194
205
|
b.match?.channel === 'pier' &&
|
|
195
206
|
(b.match?.accountId === inbound.accountId || b.match?.account === inbound.accountId)
|
|
196
207
|
);
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
routingSource = 'manual-global-bindings';
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
// Check agent list for name match (account ID == agent ID)
|
|
204
|
-
if (!finalAgentId) {
|
|
205
|
-
const nameMatch = al.find(a => a.id === inbound.accountId);
|
|
206
|
-
if (nameMatch) {
|
|
207
|
-
finalAgentId = inbound.accountId;
|
|
208
|
-
routingSource = 'manual-name-match';
|
|
209
|
-
}
|
|
208
|
+
if (binding?.agentId && binding.agentId !== 'main') {
|
|
209
|
+
finalAgentId = binding.agentId;
|
|
210
|
+
routingSource = 'manual-global-bindings-match';
|
|
210
211
|
}
|
|
211
212
|
}
|
|
212
213
|
|
|
213
|
-
//
|
|
214
|
+
// C. SDK Routing Result (if it actually found something non-default)
|
|
214
215
|
if (!finalAgentId && route.agentId && route.agentId !== 'main' && route.agentId !== 'default') {
|
|
215
216
|
finalAgentId = route.agentId;
|
|
216
217
|
routingSource = 'sdk-global-bindings';
|
|
217
218
|
}
|
|
218
219
|
|
|
219
|
-
//
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
220
|
+
// D. Name-Matching Fallback (CRITICAL: account name == agent ID)
|
|
221
|
+
// If we see account 'sunwukong', and we have an agent 'sunwukong', route there!
|
|
222
|
+
if (!finalAgentId && inbound.accountId && inbound.accountId !== 'default' && inbound.accountId !== 'main') {
|
|
223
|
+
// Check if such an agent exists in rootConfig
|
|
224
|
+
const agents = rootConfig.agents?.list || {};
|
|
225
|
+
const agentExists = Array.isArray(agents) ? agents.some(a => a.id === inbound.accountId) : !!agents[inbound.accountId];
|
|
226
|
+
|
|
227
|
+
if (agentExists) {
|
|
223
228
|
finalAgentId = inbound.accountId;
|
|
224
|
-
routingSource = '
|
|
225
|
-
} else {
|
|
226
|
-
finalAgentId = route.agentId || 'main'; // Ultimate fallback
|
|
227
|
-
routingSource = route.agentId ? 'global-bindings-fallback' : 'default-routing';
|
|
229
|
+
routingSource = 'account-agent-name-match';
|
|
228
230
|
}
|
|
229
231
|
}
|
|
230
232
|
|
|
233
|
+
// E. Ultimate Fallback
|
|
234
|
+
if (!finalAgentId) {
|
|
235
|
+
finalAgentId = route.agentId || 'main'; // Use SDK result or hard default 'main'
|
|
236
|
+
routingSource = route.agentId ? 'sdk-default-fallback' : 'hardcoded-main-fallback';
|
|
237
|
+
}
|
|
238
|
+
|
|
231
239
|
logger.info(`[pier-connector] Routing account '${inbound.accountId}' -> agent '${finalAgentId}' (Source: ${routingSource})`);
|
|
232
240
|
|
|
233
241
|
const dynamicSessionKey = `pier-job-${jobId}`;
|
|
@@ -241,7 +249,7 @@ export default function register(api) {
|
|
|
241
249
|
"=========================================",
|
|
242
250
|
"You are an autonomous AI worker on Pier. This job currently has NO assigned worker.",
|
|
243
251
|
"1. DO NOT directly solve the user's task or output the final answer right now.",
|
|
244
|
-
"2. You MUST USE the
|
|
252
|
+
"2. You MUST USE the \`pier_bid_task\` tool to send a pitch/bid to the employer explaining why you are best equipped to solve this.",
|
|
245
253
|
"3. Stop executing after submitting the bid.",
|
|
246
254
|
"4. You MUST use the Job ID provided below when calling the tool.",
|
|
247
255
|
`Job ID: ${jobId}`,
|
|
@@ -260,8 +268,9 @@ export default function register(api) {
|
|
|
260
268
|
].join('\n');
|
|
261
269
|
}
|
|
262
270
|
|
|
271
|
+
// MsgContext uses PascalCase for keys in OpenClaw V2 SDK
|
|
263
272
|
const ctxPayload = api.runtime.channel.reply.finalizeInboundContext({
|
|
264
|
-
agentId: finalAgentId, //
|
|
273
|
+
agentId: finalAgentId, // Keep lowercase here as it's the target system ID
|
|
265
274
|
Body: inbound.text,
|
|
266
275
|
BodyForAgent: inbound.text,
|
|
267
276
|
RawBody: inbound.text,
|
|
@@ -282,7 +291,8 @@ export default function register(api) {
|
|
|
282
291
|
Metadata: {
|
|
283
292
|
...metadata,
|
|
284
293
|
accountId: this.accountId,
|
|
285
|
-
pierJobId: jobId
|
|
294
|
+
pierJobId: jobId,
|
|
295
|
+
routingSource: routingSource
|
|
286
296
|
}
|
|
287
297
|
});
|
|
288
298
|
|