@gholl-studio/pier-connector 0.3.21 → 0.3.22

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.21",
4
+ "version": "0.3.22",
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
@@ -7,21 +7,22 @@ import type { InboundMessage } from './types.js';
7
7
  import { truncate } from './job-handler.js';
8
8
 
9
9
  export async function handleInbound(
10
- runtime: any, // Using context-aware runtime from gateway
10
+ ctx: any, // Gateway Context
11
11
  inbound: InboundMessage,
12
12
  jobId: string,
13
13
  robot: any,
14
14
  pierPlugin: any
15
15
  ) {
16
- const logger = runtime.log || console;
16
+ const logger = ctx.log || console;
17
+ const channelRuntime = ctx.channelRuntime;
17
18
 
18
- if (!runtime.reply) {
19
- console.error(`[pier-connector][${robot.accountId}] SDK Error: runtime.reply is not available.`);
19
+ if (!channelRuntime?.reply) {
20
+ console.error(`[pier-connector][${robot.accountId}] SDK Error: channelRuntime.reply is not available.`);
20
21
  return;
21
22
  }
22
23
 
23
24
  // 1. Resolve Account-Scoped Configuration
24
- const rootConfig = runtime.cfg || {};
25
+ const rootConfig = ctx.cfg || {};
25
26
  const accountScopedCfg = {
26
27
  ...rootConfig,
27
28
  channels: {
@@ -31,7 +32,7 @@ export async function handleInbound(
31
32
  };
32
33
 
33
34
  // 2. Resolve Agent Route
34
- const route = runtime.routing.resolveAgentRoute({
35
+ const route = channelRuntime.routing.resolveAgentRoute({
35
36
  cfg: accountScopedCfg,
36
37
  channel: 'pier',
37
38
  accountId: robot.accountId,
@@ -72,7 +73,7 @@ export async function handleInbound(
72
73
  }
73
74
 
74
75
  // 3. Finalize Context
75
- const ctxPayload = runtime.reply.finalizeInboundContext({
76
+ const ctxPayload = channelRuntime.reply.finalizeInboundContext({
76
77
  Body: inbound.body,
77
78
  BodyForAgent: inbound.body,
78
79
  RawBody: inbound.body,
@@ -102,7 +103,7 @@ export async function handleInbound(
102
103
  });
103
104
 
104
105
  // 4. Create Dispatcher
105
- const { dispatcher, markDispatchIdle } = runtime.reply.createReplyDispatcherWithTyping({
106
+ const { dispatcher, markDispatchIdle } = channelRuntime.reply.createReplyDispatcherWithTyping({
106
107
  deliver: async (payload: any, info: any) => {
107
108
  const currentMeta = robot.activeNodeJobs.get(jobId);
108
109
  const resAgent = payload.agentId || finalAgentId;
@@ -126,10 +127,10 @@ export async function handleInbound(
126
127
  });
127
128
 
128
129
  // 5. Session Recording
129
- if (runtime.session?.recordSessionMetaFromInbound) {
130
+ if (channelRuntime.session?.recordSessionMetaFromInbound) {
130
131
  try {
131
- const storePath = runtime.session.resolveStorePath(dynamicSessionKey);
132
- await runtime.session.recordSessionMetaFromInbound({
132
+ const storePath = channelRuntime.session.resolveStorePath(dynamicSessionKey);
133
+ await channelRuntime.session.recordSessionMetaFromInbound({
133
134
  storePath, sessionKey: dynamicSessionKey, ctx: ctxPayload
134
135
  });
135
136
  } catch (err: any) {
@@ -139,7 +140,7 @@ export async function handleInbound(
139
140
 
140
141
  // 6. Dispatch
141
142
  try {
142
- await runtime.reply.dispatchReplyFromConfig({
143
+ await channelRuntime.reply.dispatchReplyFromConfig({
143
144
  ctx: ctxPayload,
144
145
  cfg: accountScopedCfg,
145
146
  dispatcher,
package/src/index.ts CHANGED
@@ -168,9 +168,10 @@ const pierPlugin: ChannelPlugin<PierAccountConfig> = {
168
168
  gateway: {
169
169
  startAccount: async (ctx) => {
170
170
  const config = ctx.account;
171
- // ctx has .log, .runtime, .cfg, etc.
171
+ // Use ctx as the runtime provider as it contains .channelRuntime, .log, etc.
172
172
  const robot = new PierRobot(config, ctx as any, async (inbound, jobId) => {
173
- await handleInbound(ctx.runtime, inbound, jobId, robot, pierPlugin);
173
+ // Pass the context containing channelRuntime
174
+ await handleInbound(ctx, inbound, jobId, robot, pierPlugin);
174
175
  });
175
176
  instances.set(ctx.accountId, robot);
176
177
 
@@ -185,11 +186,17 @@ const pierPlugin: ChannelPlugin<PierAccountConfig> = {
185
186
  lastStartAt: (robot as any).lastStartAt
186
187
  } as any);
187
188
 
188
- // Note: We resolve here to signal successful startup.
189
- // The robot stays alive in the 'instances' map.
190
- // If OpenClaw requires a long-running promise, we can revert to keeping it alive,
191
- // but usually, status monitoring is enough for non-standard services.
192
- console.log(`[pier-connector][${ctx.accountId}] Startup successful and resolved.`);
189
+ // IMPORTANT: Keep startAccount promise active for the lifetime of the connection.
190
+ // If this promise resolves, the Gateway will auto-restart the account.
191
+ await new Promise<void>((resolve) => {
192
+ ctx.abortSignal.addEventListener('abort', () => {
193
+ resolve();
194
+ }, { once: true });
195
+
196
+ if (ctx.abortSignal.aborted) resolve();
197
+ });
198
+
199
+ console.log(`[pier-connector][${ctx.accountId}] Account signal aborted. Stopping...`);
193
200
  } catch (err: any) {
194
201
  (robot as any).lastError = err.message;
195
202
  ctx.setStatus({