@gholl-studio/pier-connector 0.3.11 → 0.3.13

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gholl-studio/pier-connector",
3
3
  "author": "gholl",
4
- "version": "0.3.11",
4
+ "version": "0.3.13",
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.ts",
package/src/cli.ts CHANGED
@@ -1,5 +1,10 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
+ /**
4
+ * @file cli.ts
5
+ * @description Handles the plugin's CLI command registrations and setup interaction logic.
6
+ */
7
+
3
8
  import type { PierPluginApi } from './types.js';
4
9
 
5
10
  export function registerCli(api: PierPluginApi, stats: any) {
package/src/config.ts CHANGED
@@ -1,3 +1,8 @@
1
+ /**
2
+ * @file config.ts
3
+ * @description Defines the default configuration constants and fallback values for the Pier connector.
4
+ */
5
+
1
6
  /**
2
7
  * Default configuration constants for pier-connector.
3
8
  */
package/src/inbound.ts CHANGED
@@ -1,3 +1,8 @@
1
+ /**
2
+ * @file inbound.ts
3
+ * @description Manages inbound message processing, agent routing resolution, and session context propagation.
4
+ */
5
+
1
6
  import type { PierPluginApi, InboundMessage } from './types.js';
2
7
  import { truncate } from './job-handler.js';
3
8
 
@@ -14,62 +19,32 @@ export async function handleInbound(
14
19
  return;
15
20
  }
16
21
 
17
- // 1. Resolve Global Configuration
22
+ // 1. Resolve Account-Scoped Configuration
18
23
  const rootConfig = api.config || {};
19
24
 
20
- // 2. Resolve Agent Route via SDK
25
+ /**
26
+ * ★ Multi-Account Configuration Isolation: Build account-level ClawdbotConfig
27
+ *
28
+ * In multi-account scenarios, each account can have independent agent bindings.
29
+ * The SDK's resolveAgentRoute looks into cfg.channels.pier.
30
+ * By injecting the current robot's config here, we ensure the SDK finds
31
+ * the correct agentId for this specific account.
32
+ */
33
+ const accountScopedCfg = {
34
+ ...rootConfig,
35
+ channels: { ...rootConfig.channels, pier: robot.config }
36
+ };
37
+
38
+ // 2. Resolve Agent Route via SDK with Scoped Config
21
39
  const route = api.runtime.channel.routing.resolveAgentRoute({
22
- cfg: rootConfig,
40
+ cfg: accountScopedCfg,
23
41
  channel: 'pier',
24
42
  accountId: inbound.accountId,
25
43
  peer: { kind: 'direct', id: jobId }
26
44
  });
27
45
 
28
- // 3. Robust Routing Decision Tree
29
- let finalAgentId = null;
30
- let routingSource = 'unresolved';
31
-
32
- // A. Check explicit account-level binding in plugin local config
33
- if (robot.config.agentId && robot.config.agentId !== 'main' && robot.config.agentId !== 'default') {
34
- finalAgentId = robot.config.agentId;
35
- routingSource = 'plugin-local-config';
36
- }
37
-
38
- // B. Check Global Bindings
39
- if (!finalAgentId) {
40
- const bindings = Array.isArray(rootConfig.bindings) ? rootConfig.bindings : [];
41
- const binding = bindings.find((bi: any) =>
42
- bi.match?.channel === 'pier' &&
43
- (bi.match?.accountId === inbound.accountId || bi.match?.account === inbound.accountId)
44
- );
45
- if (binding?.agentId && binding.agentId !== 'main') {
46
- finalAgentId = binding.agentId;
47
- routingSource = 'manual-global-bindings-match';
48
- }
49
- }
50
-
51
- // C. SDK Routing Result
52
- if (!finalAgentId && route.agentId && route.agentId !== 'main' && route.agentId !== 'default') {
53
- finalAgentId = route.agentId;
54
- routingSource = 'sdk-global-bindings';
55
- }
56
-
57
- // D. Name-Matching Fallback
58
- if (!finalAgentId && inbound.accountId && inbound.accountId !== 'default' && inbound.accountId !== 'main') {
59
- const agents = (rootConfig as any).agents?.list || {};
60
- const agentExists = Array.isArray(agents) ? agents.some((a: any) => a.id === inbound.accountId) : !!agents[inbound.accountId];
61
-
62
- if (agentExists) {
63
- finalAgentId = inbound.accountId;
64
- routingSource = 'account-agent-name-match';
65
- }
66
- }
67
-
68
- // E. Ultimate Fallback
69
- if (!finalAgentId) {
70
- finalAgentId = route.agentId || 'main';
71
- routingSource = route.agentId ? 'sdk-default-fallback' : 'hardcoded-main-fallback';
72
- }
46
+ const finalAgentId = route.agentId || 'main';
47
+ const routingSource = route.agentId ? 'sdk-scoped-route' : 'sdk-default-fallback';
73
48
 
74
49
  logger.info(`[pier-connector] Routing account '${inbound.accountId}' -> agent '${finalAgentId}' (Source: ${routingSource})`);
75
50
 
@@ -105,6 +80,7 @@ export async function handleInbound(
105
80
 
106
81
  const ctxPayload = api.runtime.channel.reply.finalizeInboundContext({
107
82
  AgentId: finalAgentId,
83
+ agentId: finalAgentId, // Redundant for compatibility
108
84
  Body: inbound.body,
109
85
  BodyForAgent: inbound.body,
110
86
  RawBody: inbound.body,
@@ -124,12 +100,15 @@ export async function handleInbound(
124
100
  MessageId: jobId,
125
101
  Metadata: {
126
102
  ...metadata,
103
+ agentId: finalAgentId, // Pinning in metadata
127
104
  accountId: robot.accountId,
128
105
  pierJobId: jobId,
129
106
  routingSource: routingSource
130
107
  }
131
108
  });
132
109
 
110
+ logger.info(`[pier-connector:trace] FULL DISPATCH CONTEXT for job ${jobId}: ${JSON.stringify(ctxPayload)}`);
111
+
133
112
  const { dispatcher, markDispatchIdle } = api.runtime.channel.reply.createReplyDispatcherWithTyping({
134
113
  deliver: async (payload: any) => {
135
114
  const currentMeta = robot.activeNodeJobs.get(jobId);
package/src/index.ts CHANGED
@@ -1,3 +1,8 @@
1
+ /**
2
+ * @file index.ts
3
+ * @description Main entry point for the Pier Connector plugin. Orchestrates robots, tools, and channel registration.
4
+ */
5
+
1
6
  import { definePluginEntry } from 'openclaw/plugin-sdk/plugin-entry';
2
7
  import { protocol } from '@gholl-studio/pier-sdk';
3
8
  const { createRequestPayload } = protocol;
@@ -112,8 +117,9 @@ const register = (api: PierPluginApi) => {
112
117
  },
113
118
  required: ['task']
114
119
  },
115
- async execute(_id, params) {
116
- const robot = instances.get(params.accountId || 'default') || instances.values().next().value;
120
+ async execute(_id, params, ctx: any) {
121
+ const accountId = params.accountId || ctx?.metadata?.accountId || ctx?.accountId || 'default';
122
+ const robot = instances.get(accountId) || instances.values().next().value;
117
123
  if (!robot || robot.connectionStatus !== 'connected') {
118
124
  return {
119
125
  content: [{ type: 'text', text: 'Robot not connected' }],
@@ -145,7 +151,7 @@ const register = (api: PierPluginApi) => {
145
151
  required: ['jobId', 'text']
146
152
  },
147
153
  async execute(_id, params, ctx: any) {
148
- const accountId = params.accountId || 'default';
154
+ const accountId = params.accountId || ctx?.metadata?.accountId || ctx?.accountId || 'default';
149
155
  const robot = instances.get(accountId) || instances.values().next().value;
150
156
  if (!robot || robot.connectionStatus !== 'connected') {
151
157
  return { content: [{ type: 'text', text: 'Error: Robot not connected' }], details: {} };
@@ -201,8 +207,8 @@ const register = (api: PierPluginApi) => {
201
207
  },
202
208
  required: ['jobId', ...Object.keys(extraParams)]
203
209
  },
204
- async execute(_id, params) {
205
- const accountId = params.accountId || 'default';
210
+ async execute(_id, params, ctx: any) {
211
+ const accountId = params.accountId || ctx?.metadata?.accountId || ctx?.accountId || 'default';
206
212
  const robot = instances.get(accountId) || instances.values().next().value;
207
213
  if (!robot || robot.connectionStatus !== 'connected') {
208
214
  return { content: [{ type: 'text', text: 'Error: Robot not connected' }], details: {} };
@@ -260,8 +266,9 @@ const register = (api: PierPluginApi) => {
260
266
  type: 'object',
261
267
  properties: { accountId: { type: 'string' } }
262
268
  },
263
- async execute(_id, params) {
264
- const robot = instances.get(params.accountId || 'default') || instances.values().next().value;
269
+ async execute(_id, params, ctx: any) {
270
+ const accountId = params.accountId || ctx?.metadata?.accountId || ctx?.accountId || 'default';
271
+ const robot = instances.get(accountId) || instances.values().next().value;
265
272
  if (!robot) return { content: [{ type: 'text', text: 'Error: Robot not found' }], details: {} };
266
273
  try {
267
274
  const profile = await robot.client.getUserProfile(robot.config.secretKey);
@@ -1,3 +1,8 @@
1
+ /**
2
+ * @file job-handler.ts
3
+ * @description Provides helper utilities for parsing Pier jobs, handling responses, and text manipulation.
4
+ */
5
+
1
6
  import { protocol } from '@gholl-studio/pier-sdk';
2
7
  const { normalizeInboundPayload } = protocol;
3
8
 
package/src/robot.ts CHANGED
@@ -1,3 +1,8 @@
1
+ /**
2
+ * @file robot.ts
3
+ * @description Implements the PierRobot class, managing NATS connectivity, heartbeat, and job lifecycle.
4
+ */
5
+
1
6
  import { PierClient, protocol } from '@gholl-studio/pier-sdk';
2
7
  const { createRequestPayload, createResultPayload, createErrorPayload } = protocol;
3
8
  import { parseJob, safeRespond, truncate } from './job-handler.js';
@@ -1,3 +1,8 @@
1
+ /**
2
+ * @file pier-sdk.d.ts
3
+ * @description TypeScript declaration file for the @gholl-studio/pier-sdk to support plugin compilation.
4
+ */
5
+
1
6
  declare module '@gholl-studio/pier-sdk' {
2
7
  export class PierClient {
3
8
  constructor(config: { apiUrl: string; natsUrl?: string; logger?: any });
package/src/types.ts CHANGED
@@ -1,3 +1,8 @@
1
+ /**
2
+ * @file types.ts
3
+ * @description Centralized TypeScript interface and type definitions for the Pier connector plugin.
4
+ */
5
+
1
6
  import type { OpenClawPluginApi } from 'openclaw/plugin-sdk/plugin-entry';
2
7
 
3
8
  export interface PierAccountConfig {