@gholl-studio/pier-connector 0.3.23 → 0.3.24
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 +18 -2
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.24",
|
|
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
|
@@ -102,7 +102,10 @@ export async function handleInbound(
|
|
|
102
102
|
});
|
|
103
103
|
|
|
104
104
|
// 4. Create Dispatcher
|
|
105
|
-
|
|
105
|
+
// 必须从 createReplyDispatcherWithTyping 获取 replyOptions,
|
|
106
|
+
// 它包含 SDK 内部生命周期钉子(onReplyStart / onTypingController / onTypingCleanup),
|
|
107
|
+
// 必须传入 dispatchReplyFromConfig 才能正确启动和终止 typing controller。
|
|
108
|
+
const { dispatcher, replyOptions, markDispatchIdle, markRunComplete } = channelRuntime.reply.createReplyDispatcherWithTyping({
|
|
106
109
|
deliver: async (payload: any, info: any) => {
|
|
107
110
|
const currentMeta = robot.activeNodeJobs.get(jobId);
|
|
108
111
|
const resAgent = payload.agentId || finalAgentId;
|
|
@@ -139,19 +142,32 @@ export async function handleInbound(
|
|
|
139
142
|
|
|
140
143
|
// 6. Dispatch
|
|
141
144
|
try {
|
|
142
|
-
await channelRuntime.reply.dispatchReplyFromConfig({
|
|
145
|
+
const { queuedFinal, counts } = await channelRuntime.reply.dispatchReplyFromConfig({
|
|
143
146
|
ctx: ctxPayload,
|
|
144
147
|
cfg: accountScopedCfg,
|
|
145
148
|
dispatcher,
|
|
146
149
|
replyOptions: {
|
|
150
|
+
// 必须展开 replyOptions,否则 typing controller 永远不会被启动/停止
|
|
151
|
+
// 上一条消息的会话状态就会游跍,导致 SDK 拒绝处理下一条消息
|
|
152
|
+
...replyOptions,
|
|
147
153
|
onModelSelected: (mCtx: any) => {
|
|
148
154
|
logger.info(`[pier-connector:debug] Model selected for ${jobId}: ${mCtx.provider}/${mCtx.model}`);
|
|
149
155
|
}
|
|
150
156
|
}
|
|
151
157
|
});
|
|
158
|
+
|
|
159
|
+
// 等待所有已入队的 deliver() 调用完成(参照飞书插件 dispatch.ts L128)
|
|
160
|
+
// 不调用此方法, dispatchReplyFromConfig 可能在 deliver 永远未执行的情况下返回
|
|
161
|
+
await dispatcher.waitForIdle();
|
|
162
|
+
|
|
163
|
+
logger.info(`[pier-connector] Dispatch complete for ${jobId}. queuedFinal=${queuedFinal}, counts=${JSON.stringify(counts)}`);
|
|
152
164
|
} catch (err: any) {
|
|
153
165
|
logger.error(`[pier-connector] ✖ Dispatch error for job ${jobId}: ${err.message}`);
|
|
154
166
|
} finally {
|
|
167
|
+
// markRunComplete 通知 typing controller 运行已结束。
|
|
168
|
+
// markDispatchIdle 通知 dispatcher 空闲。
|
|
169
|
+
// 必须在 finally 块不调用不等待下一条消息。
|
|
170
|
+
markRunComplete?.();
|
|
155
171
|
markDispatchIdle?.();
|
|
156
172
|
}
|
|
157
173
|
}
|