@botcord/openclaw-plugin 0.0.3 → 0.0.4
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 +35 -7
package/package.json
CHANGED
package/src/inbound.ts
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
* Inbound message dispatch — shared by websocket and polling paths.
|
|
3
3
|
* Converts BotCord messages to OpenClaw inbound format.
|
|
4
4
|
*/
|
|
5
|
-
import { readFile } from "node:fs/promises";
|
|
5
|
+
import { readFile, readdir } from "node:fs/promises";
|
|
6
|
+
import { join, dirname } from "node:path";
|
|
6
7
|
import { getBotCordRuntime } from "./runtime.js";
|
|
7
8
|
import { resolveAccountConfig } from "./config.js";
|
|
8
9
|
import { buildSessionKey } from "./session-key.js";
|
|
@@ -245,6 +246,9 @@ type DeliveryContext = {
|
|
|
245
246
|
|
|
246
247
|
/**
|
|
247
248
|
* Read deliveryContext for a session key from the session store on disk.
|
|
249
|
+
* First checks the current agent's store, then scans all agent stores
|
|
250
|
+
* (the session key may belong to a different agent than the one running
|
|
251
|
+
* this plugin).
|
|
248
252
|
* Returns undefined when the session has no recorded delivery route.
|
|
249
253
|
*/
|
|
250
254
|
async function resolveSessionDeliveryContext(
|
|
@@ -252,16 +256,40 @@ async function resolveSessionDeliveryContext(
|
|
|
252
256
|
cfg: any,
|
|
253
257
|
sessionKey: string,
|
|
254
258
|
): Promise<DeliveryContext | undefined> {
|
|
259
|
+
const tryStore = async (path: string): Promise<DeliveryContext | undefined> => {
|
|
260
|
+
try {
|
|
261
|
+
const raw = await readFile(path, "utf-8");
|
|
262
|
+
const store: Record<string, { deliveryContext?: DeliveryContext }> =
|
|
263
|
+
JSON.parse(raw);
|
|
264
|
+
const entry = store[sessionKey];
|
|
265
|
+
if (entry?.deliveryContext?.channel && entry.deliveryContext.to) {
|
|
266
|
+
return entry.deliveryContext;
|
|
267
|
+
}
|
|
268
|
+
} catch {
|
|
269
|
+
// store may not exist yet
|
|
270
|
+
}
|
|
271
|
+
return undefined;
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
// 1. Try the current agent's store first (fast path)
|
|
255
275
|
try {
|
|
256
276
|
const storePath = core.channel.session.resolveStorePath(cfg.session?.store);
|
|
257
|
-
const
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
277
|
+
const result = await tryStore(storePath);
|
|
278
|
+
if (result) return result;
|
|
279
|
+
|
|
280
|
+
// 2. Scan sibling agent stores: walk up to the agents/ dir and check each
|
|
281
|
+
// storePath is typically .../.openclaw/agents/<name>/sessions/sessions.json
|
|
282
|
+
const agentsDir = dirname(dirname(dirname(storePath)));
|
|
283
|
+
const entries = await readdir(agentsDir, { withFileTypes: true });
|
|
284
|
+
for (const entry of entries) {
|
|
285
|
+
if (!entry.isDirectory()) continue;
|
|
286
|
+
const candidate = join(agentsDir, entry.name, "sessions", "sessions.json");
|
|
287
|
+
if (candidate === storePath) continue; // already checked
|
|
288
|
+
const result = await tryStore(candidate);
|
|
289
|
+
if (result) return result;
|
|
262
290
|
}
|
|
263
291
|
} catch {
|
|
264
|
-
// best-effort
|
|
292
|
+
// best-effort
|
|
265
293
|
}
|
|
266
294
|
return undefined;
|
|
267
295
|
}
|