@gholl-studio/pier-connector 0.3.14 → 0.3.16

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/inbound.ts +51 -24
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.14",
4
+ "version": "0.3.16",
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/inbound.ts CHANGED
@@ -19,20 +19,25 @@ export async function handleInbound(
19
19
  return;
20
20
  }
21
21
 
22
- // 1. Resolve Account-Scoped Configuration
22
+ // 0. Log Online/Configured Agents
23
+ const agentsList = (api.config as any)?.agents?.list || [];
24
+ const agentIds = Array.isArray(agentsList) ? agentsList.map((a: any) => a.id) : Object.keys(agentsList);
25
+ logger.info(`[pier-connector][${robot.accountId}] Available agents in OpenClaw: ${JSON.stringify(agentIds)}`);
26
+
27
+ // 1. Resolve Account-Scoped Configuration (Standard Nested Structure)
23
28
  const rootConfig = api.config || {};
24
-
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
29
  const accountScopedCfg = {
34
30
  ...rootConfig,
35
- channels: { ...rootConfig.channels, pier: robot.config }
31
+ channels: {
32
+ ...rootConfig.channels,
33
+ pier: {
34
+ ...(rootConfig.channels?.pier || {}),
35
+ accounts: {
36
+ ...(rootConfig.channels?.pier?.accounts || {}),
37
+ [robot.accountId]: robot.config
38
+ }
39
+ }
40
+ }
36
41
  };
37
42
 
38
43
  // 2. Resolve Agent Route via SDK with Scoped Config
@@ -47,6 +52,14 @@ export async function handleInbound(
47
52
  const routingSource = route.agentId ? 'sdk-scoped-route' : 'sdk-default-fallback';
48
53
 
49
54
  logger.info(`[pier-connector] Routing account '${inbound.accountId}' -> agent '${finalAgentId}' (Source: ${routingSource})`);
55
+
56
+ // Debug: Check Agent Identity
57
+ try {
58
+ const identity = (api.runtime as any).agent.resolveAgentIdentity(finalAgentId);
59
+ logger.info(`[pier-connector:debug] Identity resolution for ${finalAgentId}: ${JSON.stringify(identity)}`);
60
+ } catch (err: any) {
61
+ logger.warn(`[pier-connector:debug] Identity resolution failed for ${finalAgentId}: ${err.message}`);
62
+ }
50
63
 
51
64
  const dynamicSessionKey = `pier-job-${jobId}`;
52
65
  const metadata = robot.activeNodeJobs.get(jobId);
@@ -109,18 +122,25 @@ export async function handleInbound(
109
122
  logger.info(`[pier-connector:trace] FULL DISPATCH CONTEXT for job ${jobId}: ${JSON.stringify(ctxPayload)}`);
110
123
 
111
124
  const { dispatcher, markDispatchIdle } = api.runtime.channel.reply.createReplyDispatcherWithTyping({
112
- deliver: async (payload: any) => {
125
+ deliver: async (payload: any, info: any) => {
113
126
  const currentMeta = robot.activeNodeJobs.get(jobId);
114
- logger.info(`[pier-connector:trace] Outbound delivery triggered for job ${jobId}. Text length: ${payload.text?.length || 0}`);
115
- await pierChannel.outbound.sendText({
116
- text: payload.text,
117
- to: `pier:${jobId}`,
118
- metadata: {
119
- ...currentMeta,
120
- accountId: robot.accountId,
121
- pierJobId: jobId
122
- },
123
- });
127
+ const respondingAgent = payload.agentId || payload.btw?.agentId || payload.channelData?.agentId || 'unknown';
128
+
129
+ logger.info(`[pier-connector:trace] Outbound delivery triggered for job ${jobId}. Type: ${info?.kind}. Responding Agent: ${respondingAgent}.`);
130
+ logger.info(`[pier-connector:debug] FULL PAYLOAD: ${JSON.stringify(payload)}`);
131
+
132
+ if (payload.text && payload.text.length > 0) {
133
+ await pierChannel.outbound.sendText({
134
+ text: payload.text,
135
+ to: `pier:${jobId}`,
136
+ metadata: {
137
+ ...currentMeta,
138
+ accountId: robot.accountId,
139
+ pierJobId: jobId,
140
+ respondingAgentId: respondingAgent
141
+ },
142
+ });
143
+ }
124
144
  }
125
145
  });
126
146
 
@@ -139,8 +159,15 @@ export async function handleInbound(
139
159
  try {
140
160
  logger.info(`[pier-connector:trace] Dispatching reply to agent ${finalAgentId}...`);
141
161
  await api.runtime.channel.reply.dispatchReplyFromConfig({
142
- ctx: ctxPayload, cfg: accountScopedCfg, dispatcher
143
- });
162
+ ctx: ctxPayload,
163
+ cfg: accountScopedCfg,
164
+ dispatcher,
165
+ replyOptions: {
166
+ onModelSelected: (mCtx: any) => {
167
+ logger.info(`[pier-connector:debug] Model selected for ${jobId}: ${mCtx.provider}/${mCtx.model} (Think: ${mCtx.thinkLevel})`);
168
+ }
169
+ }
170
+ } as any);
144
171
  logger.info(`[pier-connector:trace] dispatchReplyFromConfig completed for job ${jobId}`);
145
172
  } catch (err: any) {
146
173
  logger.error(`[pier-connector] ✖ Dispatch error for job ${jobId}: ${err.message}`);