@gholl-studio/pier-connector 0.3.15 → 0.3.17
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/inbound.ts +36 -19
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.
|
|
4
|
+
"version": "0.3.17",
|
|
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
|
@@ -24,34 +24,42 @@ export async function handleInbound(
|
|
|
24
24
|
const agentIds = Array.isArray(agentsList) ? agentsList.map((a: any) => a.id) : Object.keys(agentsList);
|
|
25
25
|
logger.info(`[pier-connector][${robot.accountId}] Available agents in OpenClaw: ${JSON.stringify(agentIds)}`);
|
|
26
26
|
|
|
27
|
-
// 1. Resolve Account-Scoped Configuration
|
|
28
|
-
const rootConfig = api.config || {};
|
|
29
|
-
|
|
27
|
+
// 1. Resolve Account-Scoped Configuration (Flat Structure for SDK)
|
|
30
28
|
/**
|
|
31
|
-
* ★ Multi-Account Configuration Isolation:
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* By injecting the current robot's config here, we ensure the SDK finds
|
|
36
|
-
* the correct agentId for this specific account.
|
|
29
|
+
* ★ Multi-Account Configuration Isolation:
|
|
30
|
+
* SDK helpers like resolveAgentRoute expect the channel config at the top level
|
|
31
|
+
* of cfg.channels.<channelName>. Replacing it with the robot's merged config
|
|
32
|
+
* ensures the SDK sees the correct agentId/dmPolicy for this specific account.
|
|
37
33
|
*/
|
|
34
|
+
const rootConfig = api.config || {};
|
|
38
35
|
const accountScopedCfg = {
|
|
39
36
|
...rootConfig,
|
|
40
|
-
channels: {
|
|
37
|
+
channels: {
|
|
38
|
+
...rootConfig.channels,
|
|
39
|
+
pier: robot.config
|
|
40
|
+
}
|
|
41
41
|
};
|
|
42
42
|
|
|
43
43
|
// 2. Resolve Agent Route via SDK with Scoped Config
|
|
44
44
|
const route = api.runtime.channel.routing.resolveAgentRoute({
|
|
45
45
|
cfg: accountScopedCfg,
|
|
46
46
|
channel: 'pier',
|
|
47
|
-
accountId:
|
|
47
|
+
accountId: robot.accountId,
|
|
48
48
|
peer: { kind: 'direct', id: jobId }
|
|
49
49
|
});
|
|
50
50
|
|
|
51
51
|
const finalAgentId = route.agentId || 'main';
|
|
52
52
|
const routingSource = route.agentId ? 'sdk-scoped-route' : 'sdk-default-fallback';
|
|
53
53
|
|
|
54
|
-
logger.info(`[pier-connector] Routing account '${
|
|
54
|
+
logger.info(`[pier-connector] Routing account '${robot.accountId}' -> agent '${finalAgentId}' (Source: ${routingSource})`);
|
|
55
|
+
|
|
56
|
+
// Debug: Check Agent Identity (Correct Signature: resolveAgentIdentity(cfg, agentId))
|
|
57
|
+
try {
|
|
58
|
+
const identity = (api.runtime as any).agent.resolveAgentIdentity(accountScopedCfg, 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
|
+
}
|
|
55
63
|
|
|
56
64
|
const dynamicSessionKey = `pier-job-${jobId}`;
|
|
57
65
|
const metadata = robot.activeNodeJobs.get(jobId);
|
|
@@ -87,13 +95,13 @@ export async function handleInbound(
|
|
|
87
95
|
Body: inbound.body,
|
|
88
96
|
BodyForAgent: inbound.body,
|
|
89
97
|
RawBody: inbound.body,
|
|
90
|
-
From: inbound.senderId
|
|
98
|
+
From: `pier:${inbound.senderId}`,
|
|
91
99
|
To: `chat:${jobId}`,
|
|
92
100
|
SessionKey: dynamicSessionKey,
|
|
93
|
-
AccountId:
|
|
101
|
+
AccountId: robot.accountId,
|
|
94
102
|
ChatType: 'direct',
|
|
95
103
|
SenderId: inbound.senderId,
|
|
96
|
-
SenderName:
|
|
104
|
+
SenderName: inbound.senderId, // Use senderId as name if unknown
|
|
97
105
|
Provider: 'pier',
|
|
98
106
|
Surface: 'pier',
|
|
99
107
|
OriginatingChannel: 'pier',
|
|
@@ -116,9 +124,11 @@ export async function handleInbound(
|
|
|
116
124
|
const { dispatcher, markDispatchIdle } = api.runtime.channel.reply.createReplyDispatcherWithTyping({
|
|
117
125
|
deliver: async (payload: any, info: any) => {
|
|
118
126
|
const currentMeta = robot.activeNodeJobs.get(jobId);
|
|
119
|
-
const respondingAgent = payload.
|
|
127
|
+
const respondingAgent = payload.agentId || payload.btw?.agentId || payload.channelData?.agentId || finalAgentId;
|
|
120
128
|
|
|
121
|
-
logger.info(`[pier-connector:trace] Outbound delivery triggered for job ${jobId}. Type: ${info?.kind}. Responding Agent: ${respondingAgent}
|
|
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
|
+
|
|
122
132
|
if (payload.text && payload.text.length > 0) {
|
|
123
133
|
await pierChannel.outbound.sendText({
|
|
124
134
|
text: payload.text,
|
|
@@ -149,8 +159,15 @@ export async function handleInbound(
|
|
|
149
159
|
try {
|
|
150
160
|
logger.info(`[pier-connector:trace] Dispatching reply to agent ${finalAgentId}...`);
|
|
151
161
|
await api.runtime.channel.reply.dispatchReplyFromConfig({
|
|
152
|
-
ctx: ctxPayload,
|
|
153
|
-
|
|
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);
|
|
154
171
|
logger.info(`[pier-connector:trace] dispatchReplyFromConfig completed for job ${jobId}`);
|
|
155
172
|
} catch (err: any) {
|
|
156
173
|
logger.error(`[pier-connector] ✖ Dispatch error for job ${jobId}: ${err.message}`);
|