@gholl-studio/pier-connector 0.2.36 → 0.2.38

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 +87 -3
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.38",
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);
@@ -912,7 +936,67 @@ export default function register(api) {
912
936
  },
913
937
  });
914
938
 
915
- // ── 5. Register CLI Setup Command ──────────────────────────────────
939
+ // ── 5. Register Interactive Channel Login ─────────────────────────
940
+
941
+ if (typeof api.bindLogin === 'function') {
942
+ api.bindLogin({
943
+ channel: 'pier',
944
+ handler: async () => {
945
+ console.log('\n🚢 \x1b[1m\x1b[36mPier Channel Login\x1b[0m');
946
+
947
+ const answers = await inquirer.prompt([
948
+ {
949
+ type: 'input',
950
+ name: 'accountId',
951
+ message: 'Account Name (e.g., sunwukong, jolin):',
952
+ default: 'default',
953
+ validate: (input) => input.trim().length > 0 || 'Account name is required'
954
+ },
955
+ {
956
+ type: 'input',
957
+ name: 'pierApiUrl',
958
+ message: 'Pier API URL:',
959
+ default: DEFAULTS.PIER_API_URL
960
+ },
961
+ {
962
+ type: 'input',
963
+ name: 'nodeId',
964
+ message: 'Bot Node ID (UUID):',
965
+ validate: (input) => input.trim().length > 0 || 'Node ID is required'
966
+ },
967
+ {
968
+ type: 'password',
969
+ name: 'secretKey',
970
+ message: 'Bot Secret Key:',
971
+ validate: (input) => input.trim().length > 0 || 'Secret Key is required'
972
+ },
973
+ ]);
974
+
975
+ console.log('\n\x1b[36mVerifying connection...\x1b[0m');
976
+ try {
977
+ const tempClient = new PierClient({ apiUrl: answers.pierApiUrl });
978
+ // Verify credentials via a simple heartbeat
979
+ await tempClient.heartbeat(answers.nodeId, answers.secretKey);
980
+
981
+ console.log('\x1b[32m✔ Verified successfully!\x1b[0m');
982
+
983
+ return {
984
+ accountId: answers.accountId,
985
+ config: {
986
+ enabled: true,
987
+ pierApiUrl: answers.pierApiUrl,
988
+ nodeId: answers.nodeId,
989
+ secretKey: answers.secretKey
990
+ }
991
+ };
992
+ } catch (err) {
993
+ throw new Error(`Failed to verify Pier credentials: ${err.message}`);
994
+ }
995
+ }
996
+ });
997
+ }
998
+
999
+ // ── 6. Register CLI Setup Command ──────────────────────────────────
916
1000
 
917
1001
  api.registerCli(
918
1002
  ({ program }) => {