@xmoxmo/bncr 0.0.5 → 0.0.6
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/index.ts +28 -2
- package/package.json +1 -1
- package/src/channel.ts +2521 -2252
- package/src/core/config-schema.ts +11 -0
package/index.ts
CHANGED
|
@@ -5,17 +5,43 @@ import {
|
|
|
5
5
|
import { BncrConfigSchema } from "./src/core/config-schema.js";
|
|
6
6
|
import { createBncrBridge, createBncrChannelPlugin } from "./src/channel.js";
|
|
7
7
|
|
|
8
|
+
type BridgeSingleton = ReturnType<typeof createBncrBridge>;
|
|
9
|
+
|
|
10
|
+
const getBridgeSingleton = (api: OpenClawPluginApi) => {
|
|
11
|
+
const g = globalThis as typeof globalThis & { __bncrBridge?: BridgeSingleton };
|
|
12
|
+
if (!g.__bncrBridge) g.__bncrBridge = createBncrBridge(api);
|
|
13
|
+
return g.__bncrBridge;
|
|
14
|
+
};
|
|
15
|
+
|
|
8
16
|
const plugin = {
|
|
9
17
|
id: "bncr",
|
|
10
18
|
name: "Bncr",
|
|
11
19
|
description: "Bncr channel plugin",
|
|
12
20
|
configSchema: BncrConfigSchema,
|
|
13
21
|
register(api: OpenClawPluginApi) {
|
|
14
|
-
const bridge =
|
|
22
|
+
const bridge = getBridgeSingleton(api);
|
|
23
|
+
const debugLog = (...args: any[]) => {
|
|
24
|
+
if (!bridge.isDebugEnabled?.()) return;
|
|
25
|
+
api.logger.info?.(...args);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
debugLog(`bncr plugin register bridge=${(bridge as any)?.bridgeId || 'unknown'}`);
|
|
29
|
+
|
|
30
|
+
const resolveDebug = async () => {
|
|
31
|
+
try {
|
|
32
|
+
const cfg = await api.runtime.config.loadConfig();
|
|
33
|
+
return Boolean((cfg as any)?.channels?.bncr?.debug?.verbose);
|
|
34
|
+
} catch {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
15
38
|
|
|
16
39
|
api.registerService({
|
|
17
40
|
id: "bncr-bridge-service",
|
|
18
|
-
start:
|
|
41
|
+
start: async (ctx) => {
|
|
42
|
+
const debug = await resolveDebug();
|
|
43
|
+
await bridge.startService(ctx, debug);
|
|
44
|
+
},
|
|
19
45
|
stop: bridge.stopService,
|
|
20
46
|
});
|
|
21
47
|
|