openclaw-remote 0.5.2 → 0.5.3
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/dist/index.js +65 -47
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2798,6 +2798,24 @@ var { setRuntime: setRemoteRuntime, getRuntime: getRemoteRuntime } = createPlugi
|
|
|
2798
2798
|
);
|
|
2799
2799
|
|
|
2800
2800
|
// src/channel.ts
|
|
2801
|
+
function readJsonBody(req) {
|
|
2802
|
+
return new Promise((resolve, reject) => {
|
|
2803
|
+
const chunks = [];
|
|
2804
|
+
req.on("data", (chunk) => chunks.push(chunk));
|
|
2805
|
+
req.on("end", () => {
|
|
2806
|
+
try {
|
|
2807
|
+
resolve(JSON.parse(Buffer.concat(chunks).toString("utf-8")));
|
|
2808
|
+
} catch {
|
|
2809
|
+
resolve(null);
|
|
2810
|
+
}
|
|
2811
|
+
});
|
|
2812
|
+
req.on("error", reject);
|
|
2813
|
+
});
|
|
2814
|
+
}
|
|
2815
|
+
function respondJson(res, status, data) {
|
|
2816
|
+
res.writeHead(status, { "Content-Type": "application/json" });
|
|
2817
|
+
res.end(JSON.stringify(data));
|
|
2818
|
+
}
|
|
2801
2819
|
var CHANNEL_ID = "remote";
|
|
2802
2820
|
var activeRouteUnregisters = /* @__PURE__ */ new Map();
|
|
2803
2821
|
function waitUntilAbort(signal, onAbort) {
|
|
@@ -2996,62 +3014,62 @@ function createRemotePlugin() {
|
|
|
2996
3014
|
log?.info?.(
|
|
2997
3015
|
`Starting Remote channel (account: ${accountId}, webhookPath: ${account.webhookPath})`
|
|
2998
3016
|
);
|
|
2999
|
-
const handler = async (req) => {
|
|
3017
|
+
const handler = async (req, res) => {
|
|
3000
3018
|
if (req.method !== "POST") {
|
|
3001
|
-
|
|
3019
|
+
respondJson(res, 405, { error: "Method not allowed" });
|
|
3020
|
+
return;
|
|
3002
3021
|
}
|
|
3003
|
-
const payload = req
|
|
3022
|
+
const payload = await readJsonBody(req);
|
|
3004
3023
|
if (!payload || !payload.event || !payload.task_id) {
|
|
3005
|
-
|
|
3024
|
+
respondJson(res, 400, { error: "Invalid payload: missing event or task_id" });
|
|
3025
|
+
return;
|
|
3006
3026
|
}
|
|
3007
3027
|
log?.info?.(`Webhook received: ${payload.event} for task ${payload.task_id} (agent: ${payload.agent_name})`);
|
|
3028
|
+
respondJson(res, 200, { ok: true, event: payload.event });
|
|
3008
3029
|
const body = formatWebhookEvent(payload);
|
|
3009
3030
|
const sessionKey = `remote:${account.accountId}:${payload.task_id}`;
|
|
3010
|
-
|
|
3011
|
-
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
|
|
3030
|
-
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
|
|
3038
|
-
|
|
3039
|
-
|
|
3040
|
-
await postComment(account, payload.task_id, text);
|
|
3041
|
-
}
|
|
3042
|
-
},
|
|
3043
|
-
onReplyStart: () => {
|
|
3044
|
-
log?.info?.(`Agent reply started for task ${payload.task_id}`);
|
|
3031
|
+
try {
|
|
3032
|
+
const rt = getRemoteRuntime();
|
|
3033
|
+
const currentCfg = await rt.config.loadConfig();
|
|
3034
|
+
const msgCtx = rt.channel.reply.finalizeInboundContext({
|
|
3035
|
+
Body: body,
|
|
3036
|
+
RawBody: body,
|
|
3037
|
+
CommandBody: body,
|
|
3038
|
+
From: `remote:${payload.task_id}`,
|
|
3039
|
+
To: `remote:${account.accountId}`,
|
|
3040
|
+
SessionKey: sessionKey,
|
|
3041
|
+
AccountId: account.accountId,
|
|
3042
|
+
OriginatingChannel: CHANNEL_ID,
|
|
3043
|
+
OriginatingTo: `remote:${payload.task_id}`,
|
|
3044
|
+
ChatType: "direct",
|
|
3045
|
+
SenderName: payload.author_name || "Remote Board",
|
|
3046
|
+
SenderId: payload.task_id,
|
|
3047
|
+
Provider: CHANNEL_ID,
|
|
3048
|
+
Surface: CHANNEL_ID,
|
|
3049
|
+
ConversationLabel: payload.task_title || `Task ${payload.task_id}`,
|
|
3050
|
+
Timestamp: Date.now()
|
|
3051
|
+
});
|
|
3052
|
+
await rt.channel.reply.dispatchReplyWithBufferedBlockDispatcher({
|
|
3053
|
+
ctx: msgCtx,
|
|
3054
|
+
cfg: currentCfg,
|
|
3055
|
+
dispatcherOptions: {
|
|
3056
|
+
deliver: async (deliverPayload) => {
|
|
3057
|
+
if (deliverPayload.isReasoning) return;
|
|
3058
|
+
const text = deliverPayload?.text ?? deliverPayload?.body;
|
|
3059
|
+
if (text) {
|
|
3060
|
+
await postComment(account, payload.task_id, text);
|
|
3045
3061
|
}
|
|
3062
|
+
},
|
|
3063
|
+
onReplyStart: () => {
|
|
3064
|
+
log?.info?.(`Agent reply started for task ${payload.task_id}`);
|
|
3046
3065
|
}
|
|
3047
|
-
}
|
|
3048
|
-
}
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
)
|
|
3052
|
-
|
|
3053
|
-
}
|
|
3054
|
-
return { status: 200, body: { ok: true, event: payload.event } };
|
|
3066
|
+
}
|
|
3067
|
+
});
|
|
3068
|
+
} catch (err) {
|
|
3069
|
+
log?.error?.(
|
|
3070
|
+
`Error dispatching webhook event: ${err instanceof Error ? err.message : String(err)}`
|
|
3071
|
+
);
|
|
3072
|
+
}
|
|
3055
3073
|
};
|
|
3056
3074
|
const routeKey = `${accountId}:${account.webhookPath}`;
|
|
3057
3075
|
const prevUnregister = activeRouteUnregisters.get(routeKey);
|