@syengup/friday-channel-next 0.0.40 → 0.0.41
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.
|
@@ -1,16 +1,42 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
2
|
import { readdirSync } from "node:fs";
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
-
const OPENCLAW_DIST = "/opt/homebrew/lib/node_modules/openclaw/dist";
|
|
3
|
+
import { join, dirname } from "node:path";
|
|
5
4
|
let cache = null;
|
|
5
|
+
function resolveOpenClawDist() {
|
|
6
|
+
// Resolve any known openclaw SDK module to find the dist directory.
|
|
7
|
+
// This works cross-platform since the gateway's module loader
|
|
8
|
+
// maps `openclaw/*` to the installed dist.
|
|
9
|
+
const gatewayRequire = createRequire(import.meta.url);
|
|
10
|
+
try {
|
|
11
|
+
const corePath = gatewayRequire.resolve("openclaw/plugin-sdk/core");
|
|
12
|
+
return dirname(dirname(corePath)); // dist/plugin-sdk/core.js → dist/
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
// Fallback for when the plugin runs outside the gateway process.
|
|
16
|
+
// Probe common install paths.
|
|
17
|
+
for (const root of [
|
|
18
|
+
join(process.env.APPDATA ?? "", "npm/node_modules/openclaw/dist"), // Windows npm -g
|
|
19
|
+
"/opt/homebrew/lib/node_modules/openclaw/dist", // macOS Homebrew
|
|
20
|
+
"/home/linuxbrew/.linuxbrew/lib/node_modules/openclaw/dist", // Linux Homebrew
|
|
21
|
+
"/usr/local/lib/node_modules/openclaw/dist", // Unix npm -g
|
|
22
|
+
]) {
|
|
23
|
+
try {
|
|
24
|
+
readdirSync(root);
|
|
25
|
+
return root;
|
|
26
|
+
}
|
|
27
|
+
catch { }
|
|
28
|
+
}
|
|
29
|
+
throw new Error("OpenClaw dist directory not found");
|
|
30
|
+
}
|
|
31
|
+
}
|
|
6
32
|
export function loadNodePairingModule() {
|
|
7
33
|
if (cache)
|
|
8
34
|
return cache;
|
|
9
|
-
const
|
|
35
|
+
const dist = resolveOpenClawDist();
|
|
36
|
+
const file = readdirSync(dist).find((f) => f.startsWith("node-pairing-") && f.endsWith(".js") && !f.includes("authz"));
|
|
10
37
|
if (!file)
|
|
11
38
|
throw new Error("node-pairing module not found in OpenClaw dist");
|
|
12
|
-
|
|
13
|
-
cache = gatewayRequire(`./${file.replace(/\.js$/, "")}`);
|
|
39
|
+
cache = createRequire(join(dist, "_"))(`./${file.replace(/\.js$/, "")}`);
|
|
14
40
|
return cache;
|
|
15
41
|
}
|
|
16
42
|
/** Vitest-only: inject mock pairing functions. */
|
package/package.json
CHANGED
|
@@ -1,22 +1,43 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
2
|
import { readdirSync } from "node:fs";
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
-
|
|
5
|
-
const OPENCLAW_DIST = "/opt/homebrew/lib/node_modules/openclaw/dist";
|
|
3
|
+
import { join, dirname } from "node:path";
|
|
6
4
|
|
|
7
5
|
let cache: { listNodePairing: Function; approveNodePairing: Function } | null = null;
|
|
8
6
|
|
|
7
|
+
function resolveOpenClawDist(): string {
|
|
8
|
+
// Resolve any known openclaw SDK module to find the dist directory.
|
|
9
|
+
// This works cross-platform since the gateway's module loader
|
|
10
|
+
// maps `openclaw/*` to the installed dist.
|
|
11
|
+
const gatewayRequire = createRequire(import.meta.url);
|
|
12
|
+
try {
|
|
13
|
+
const corePath = gatewayRequire.resolve("openclaw/plugin-sdk/core");
|
|
14
|
+
return dirname(dirname(corePath)); // dist/plugin-sdk/core.js → dist/
|
|
15
|
+
} catch {
|
|
16
|
+
// Fallback for when the plugin runs outside the gateway process.
|
|
17
|
+
// Probe common install paths.
|
|
18
|
+
for (const root of [
|
|
19
|
+
join(process.env.APPDATA ?? "", "npm/node_modules/openclaw/dist"), // Windows npm -g
|
|
20
|
+
"/opt/homebrew/lib/node_modules/openclaw/dist", // macOS Homebrew
|
|
21
|
+
"/home/linuxbrew/.linuxbrew/lib/node_modules/openclaw/dist", // Linux Homebrew
|
|
22
|
+
"/usr/local/lib/node_modules/openclaw/dist", // Unix npm -g
|
|
23
|
+
]) {
|
|
24
|
+
try { readdirSync(root); return root; } catch {}
|
|
25
|
+
}
|
|
26
|
+
throw new Error("OpenClaw dist directory not found");
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
9
30
|
export function loadNodePairingModule(): {
|
|
10
31
|
listNodePairing: Function;
|
|
11
32
|
approveNodePairing: Function;
|
|
12
33
|
} {
|
|
13
34
|
if (cache) return cache;
|
|
14
|
-
const
|
|
35
|
+
const dist = resolveOpenClawDist();
|
|
36
|
+
const file = readdirSync(dist).find(
|
|
15
37
|
(f) => f.startsWith("node-pairing-") && f.endsWith(".js") && !f.includes("authz"),
|
|
16
38
|
);
|
|
17
39
|
if (!file) throw new Error("node-pairing module not found in OpenClaw dist");
|
|
18
|
-
|
|
19
|
-
cache = gatewayRequire(`./${file.replace(/\.js$/, "")}`);
|
|
40
|
+
cache = createRequire(join(dist, "_"))(`./${file.replace(/\.js$/, "")}`);
|
|
20
41
|
return cache!;
|
|
21
42
|
}
|
|
22
43
|
|