@alfe.ai/openclaw-webhooks 0.0.18 → 0.0.19

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/plugin.cjs CHANGED
@@ -1,5 +1,6 @@
1
1
  let _alfe_ai_webhooks = require("@alfe.ai/webhooks");
2
2
  let _alfe_ai_config = require("@alfe.ai/config");
3
+ let _alfe_ai_openclaw_plugin_kit = require("@alfe.ai/openclaw-plugin-kit");
3
4
  //#region src/plugin.ts
4
5
  /**
5
6
  * @alfe.ai/openclaw-webhooks — OpenClaw webhooks plugin.
@@ -15,37 +16,9 @@ let _alfe_ai_config = require("@alfe.ai/config");
15
16
  */
16
17
  const pkg = (0, require("node:module").createRequire)(require("url").pathToFileURL(__filename).href)("../package.json");
17
18
  const WEBHOOKS_CAPABILITIES = ["webhooks.receive", "webhooks.manage"];
19
+ const WEBHOOKS_ACTIVATION_KEY = (0, _alfe_ai_openclaw_plugin_kit.getActivationKey)("webhooks");
18
20
  let daemonIpcClient = null;
19
21
  let webhooksClient = null;
20
- /**
21
- * Attempt to connect to the Alfe daemon IPC socket.
22
- */
23
- async function connectToDaemon(socketPath, log) {
24
- try {
25
- const IPCClientCtor = (await import("@alfe.ai/openclaw")).IPCClient;
26
- const client = new IPCClientCtor(socketPath, log);
27
- client.on("connected", async () => {
28
- log.info("Connected to Alfe daemon — registering webhooks capabilities...");
29
- const response = await client.request("capability.register", {
30
- plugin: "@alfe.ai/openclaw-webhooks",
31
- capabilities: [...WEBHOOKS_CAPABILITIES]
32
- });
33
- if (response.ok) log.info("Webhooks capabilities registered with daemon");
34
- else log.warn(`Failed to register webhooks capabilities: ${response.error?.message ?? "unknown"}`);
35
- });
36
- client.on("disconnected", (reason) => {
37
- log.warn(`Disconnected from Alfe daemon: ${String(reason)}`);
38
- });
39
- client.on("error", (err) => {
40
- log.debug(`Daemon IPC error: ${err.message}`);
41
- });
42
- client.start();
43
- return client;
44
- } catch {
45
- log.info("Alfe daemon not available — webhooks plugin running standalone");
46
- return null;
47
- }
48
- }
49
22
  const plugin = {
50
23
  id: "@alfe.ai/openclaw-webhooks",
51
24
  name: "Alfe Webhooks Plugin",
@@ -55,50 +28,50 @@ const plugin = {
55
28
  const log = api.logger;
56
29
  const pluginConfig = (api.config ?? {}).plugins?.entries?.["@alfe.ai/openclaw-webhooks"]?.config ?? {};
57
30
  const startWebhooksService = () => {
58
- if (globalThis.__alfeWebhooksPluginActivated === true) {
59
- log.debug("Alfe Webhooks plugin already activated — skipping duplicate");
60
- return;
61
- }
62
- globalThis.__alfeWebhooksPluginActivated = true;
63
- log.info("Alfe Webhooks plugin activating...");
64
- let alfeConfig = null;
65
- try {
66
- alfeConfig = (0, _alfe_ai_config.resolveConfig)();
67
- } catch {
68
- log.info("Could not resolve Alfe config — daemon IPC and webhooks WS auth unavailable");
69
- }
70
- connectToDaemon(pluginConfig.daemonSocket ?? alfeConfig?.socketPath ?? _alfe_ai_config.DEFAULT_SOCKET_PATH, log).then((client) => {
71
- daemonIpcClient = client;
72
- }).catch((err) => {
73
- log.debug(`Daemon connect failed: ${err.message}`);
74
- });
75
- const webhooksWsUrl = pluginConfig.webhooksWsUrl;
76
- const apiKey = alfeConfig?.apiKey;
77
- if (webhooksWsUrl && apiKey) {
78
- log.info(`Connecting to webhooks service: ${webhooksWsUrl}`);
79
- webhooksClient = new _alfe_ai_webhooks.WebhooksServiceClient({
80
- wsUrl: webhooksWsUrl,
81
- apiKey,
82
- onWebhook: (delivery) => {
83
- log.info(`Webhook received: ${delivery.name} (${delivery.webhookId}) provider=${delivery.provider}`);
84
- if (daemonIpcClient) daemonIpcClient.request("event.emit", {
85
- event: "webhook.received",
86
- payload: delivery
87
- }).catch((err) => {
88
- log.debug(`Failed to emit webhook event to daemon: ${err.message}`);
89
- });
90
- },
91
- onConnectionChange: (connected) => {
92
- log.info(`Webhooks service connection: ${connected ? "connected" : "disconnected"}`);
93
- },
94
- logger: log
31
+ (0, _alfe_ai_openclaw_plugin_kit.guardedStart)(WEBHOOKS_ACTIVATION_KEY, log, () => {
32
+ log.info("Alfe Webhooks plugin activating...");
33
+ let alfeConfig = null;
34
+ try {
35
+ alfeConfig = (0, _alfe_ai_config.resolveConfig)();
36
+ } catch {
37
+ log.info("Could not resolve Alfe config — daemon IPC and webhooks WS auth unavailable");
38
+ }
39
+ (0, _alfe_ai_openclaw_plugin_kit.connectToDaemon)(pluginConfig.daemonSocket ?? alfeConfig?.socketPath ?? _alfe_ai_config.DEFAULT_SOCKET_PATH, log, {
40
+ pluginId: "@alfe.ai/openclaw-webhooks",
41
+ capabilities: WEBHOOKS_CAPABILITIES,
42
+ standaloneNote: "Alfe daemon not available — webhooks plugin running standalone"
43
+ }).then((client) => {
44
+ daemonIpcClient = client;
45
+ }).catch((err) => {
46
+ log.debug(`Daemon connect failed: ${err.message}`);
95
47
  });
96
- webhooksClient.start();
97
- log.info("Webhooks service client started");
98
- } else log.info("Webhooks service URL not configured — running without webhooks relay");
48
+ const webhooksWsUrl = pluginConfig.webhooksWsUrl;
49
+ const apiKey = alfeConfig?.apiKey;
50
+ if (webhooksWsUrl && apiKey) {
51
+ log.info(`Connecting to webhooks service: ${webhooksWsUrl}`);
52
+ webhooksClient = new _alfe_ai_webhooks.WebhooksServiceClient({
53
+ wsUrl: webhooksWsUrl,
54
+ apiKey,
55
+ onWebhook: (delivery) => {
56
+ log.info(`Webhook received: ${delivery.name} (${delivery.webhookId}) provider=${delivery.provider}`);
57
+ if (daemonIpcClient) daemonIpcClient.request("event.emit", {
58
+ event: "webhook.received",
59
+ payload: delivery
60
+ }).catch((err) => {
61
+ log.debug(`Failed to emit webhook event to daemon: ${err.message}`);
62
+ });
63
+ },
64
+ onConnectionChange: (connected) => {
65
+ log.info(`Webhooks service connection: ${connected ? "connected" : "disconnected"}`);
66
+ },
67
+ logger: log
68
+ });
69
+ webhooksClient.start();
70
+ log.info("Webhooks service client started");
71
+ } else log.info("Webhooks service URL not configured — running without webhooks relay");
72
+ });
99
73
  };
100
74
  const stopWebhooksService = () => {
101
- globalThis.__alfeWebhooksPluginActivated = false;
102
75
  if (webhooksClient) {
103
76
  webhooksClient.stop();
104
77
  webhooksClient = null;
@@ -113,6 +86,7 @@ const plugin = {
113
86
  }
114
87
  daemonIpcClient = null;
115
88
  }
89
+ (0, _alfe_ai_openclaw_plugin_kit.resetActivation)(WEBHOOKS_ACTIVATION_KEY);
116
90
  log.info("Alfe Webhooks plugin deactivated");
117
91
  };
118
92
  if (typeof api.registerGatewayMethod === "function") {
@@ -189,7 +163,6 @@ const plugin = {
189
163
  log.info("Alfe Webhooks plugin activated");
190
164
  },
191
165
  deactivate(api) {
192
- globalThis.__alfeWebhooksPluginActivated = false;
193
166
  const log = api.logger;
194
167
  log.info("Alfe Webhooks plugin deactivating...");
195
168
  if (webhooksClient) {
@@ -206,6 +179,7 @@ const plugin = {
206
179
  }
207
180
  daemonIpcClient = null;
208
181
  }
182
+ (0, _alfe_ai_openclaw_plugin_kit.resetActivation)(WEBHOOKS_ACTIVATION_KEY);
209
183
  log.info("Alfe Webhooks plugin deactivated");
210
184
  }
211
185
  };
package/dist/plugin.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { createRequire } from "node:module";
2
2
  import { WebhooksServiceClient } from "@alfe.ai/webhooks";
3
3
  import { DEFAULT_SOCKET_PATH, resolveConfig } from "@alfe.ai/config";
4
+ import { connectToDaemon, getActivationKey, guardedStart, resetActivation } from "@alfe.ai/openclaw-plugin-kit";
4
5
  //#region src/plugin.ts
5
6
  /**
6
7
  * @alfe.ai/openclaw-webhooks — OpenClaw webhooks plugin.
@@ -16,37 +17,9 @@ import { DEFAULT_SOCKET_PATH, resolveConfig } from "@alfe.ai/config";
16
17
  */
17
18
  const pkg = createRequire(import.meta.url)("../package.json");
18
19
  const WEBHOOKS_CAPABILITIES = ["webhooks.receive", "webhooks.manage"];
20
+ const WEBHOOKS_ACTIVATION_KEY = getActivationKey("webhooks");
19
21
  let daemonIpcClient = null;
20
22
  let webhooksClient = null;
21
- /**
22
- * Attempt to connect to the Alfe daemon IPC socket.
23
- */
24
- async function connectToDaemon(socketPath, log) {
25
- try {
26
- const IPCClientCtor = (await import("@alfe.ai/openclaw")).IPCClient;
27
- const client = new IPCClientCtor(socketPath, log);
28
- client.on("connected", async () => {
29
- log.info("Connected to Alfe daemon — registering webhooks capabilities...");
30
- const response = await client.request("capability.register", {
31
- plugin: "@alfe.ai/openclaw-webhooks",
32
- capabilities: [...WEBHOOKS_CAPABILITIES]
33
- });
34
- if (response.ok) log.info("Webhooks capabilities registered with daemon");
35
- else log.warn(`Failed to register webhooks capabilities: ${response.error?.message ?? "unknown"}`);
36
- });
37
- client.on("disconnected", (reason) => {
38
- log.warn(`Disconnected from Alfe daemon: ${String(reason)}`);
39
- });
40
- client.on("error", (err) => {
41
- log.debug(`Daemon IPC error: ${err.message}`);
42
- });
43
- client.start();
44
- return client;
45
- } catch {
46
- log.info("Alfe daemon not available — webhooks plugin running standalone");
47
- return null;
48
- }
49
- }
50
23
  const plugin = {
51
24
  id: "@alfe.ai/openclaw-webhooks",
52
25
  name: "Alfe Webhooks Plugin",
@@ -56,50 +29,50 @@ const plugin = {
56
29
  const log = api.logger;
57
30
  const pluginConfig = (api.config ?? {}).plugins?.entries?.["@alfe.ai/openclaw-webhooks"]?.config ?? {};
58
31
  const startWebhooksService = () => {
59
- if (globalThis.__alfeWebhooksPluginActivated === true) {
60
- log.debug("Alfe Webhooks plugin already activated — skipping duplicate");
61
- return;
62
- }
63
- globalThis.__alfeWebhooksPluginActivated = true;
64
- log.info("Alfe Webhooks plugin activating...");
65
- let alfeConfig = null;
66
- try {
67
- alfeConfig = resolveConfig();
68
- } catch {
69
- log.info("Could not resolve Alfe config — daemon IPC and webhooks WS auth unavailable");
70
- }
71
- connectToDaemon(pluginConfig.daemonSocket ?? alfeConfig?.socketPath ?? DEFAULT_SOCKET_PATH, log).then((client) => {
72
- daemonIpcClient = client;
73
- }).catch((err) => {
74
- log.debug(`Daemon connect failed: ${err.message}`);
75
- });
76
- const webhooksWsUrl = pluginConfig.webhooksWsUrl;
77
- const apiKey = alfeConfig?.apiKey;
78
- if (webhooksWsUrl && apiKey) {
79
- log.info(`Connecting to webhooks service: ${webhooksWsUrl}`);
80
- webhooksClient = new WebhooksServiceClient({
81
- wsUrl: webhooksWsUrl,
82
- apiKey,
83
- onWebhook: (delivery) => {
84
- log.info(`Webhook received: ${delivery.name} (${delivery.webhookId}) provider=${delivery.provider}`);
85
- if (daemonIpcClient) daemonIpcClient.request("event.emit", {
86
- event: "webhook.received",
87
- payload: delivery
88
- }).catch((err) => {
89
- log.debug(`Failed to emit webhook event to daemon: ${err.message}`);
90
- });
91
- },
92
- onConnectionChange: (connected) => {
93
- log.info(`Webhooks service connection: ${connected ? "connected" : "disconnected"}`);
94
- },
95
- logger: log
32
+ guardedStart(WEBHOOKS_ACTIVATION_KEY, log, () => {
33
+ log.info("Alfe Webhooks plugin activating...");
34
+ let alfeConfig = null;
35
+ try {
36
+ alfeConfig = resolveConfig();
37
+ } catch {
38
+ log.info("Could not resolve Alfe config — daemon IPC and webhooks WS auth unavailable");
39
+ }
40
+ connectToDaemon(pluginConfig.daemonSocket ?? alfeConfig?.socketPath ?? DEFAULT_SOCKET_PATH, log, {
41
+ pluginId: "@alfe.ai/openclaw-webhooks",
42
+ capabilities: WEBHOOKS_CAPABILITIES,
43
+ standaloneNote: "Alfe daemon not available — webhooks plugin running standalone"
44
+ }).then((client) => {
45
+ daemonIpcClient = client;
46
+ }).catch((err) => {
47
+ log.debug(`Daemon connect failed: ${err.message}`);
96
48
  });
97
- webhooksClient.start();
98
- log.info("Webhooks service client started");
99
- } else log.info("Webhooks service URL not configured — running without webhooks relay");
49
+ const webhooksWsUrl = pluginConfig.webhooksWsUrl;
50
+ const apiKey = alfeConfig?.apiKey;
51
+ if (webhooksWsUrl && apiKey) {
52
+ log.info(`Connecting to webhooks service: ${webhooksWsUrl}`);
53
+ webhooksClient = new WebhooksServiceClient({
54
+ wsUrl: webhooksWsUrl,
55
+ apiKey,
56
+ onWebhook: (delivery) => {
57
+ log.info(`Webhook received: ${delivery.name} (${delivery.webhookId}) provider=${delivery.provider}`);
58
+ if (daemonIpcClient) daemonIpcClient.request("event.emit", {
59
+ event: "webhook.received",
60
+ payload: delivery
61
+ }).catch((err) => {
62
+ log.debug(`Failed to emit webhook event to daemon: ${err.message}`);
63
+ });
64
+ },
65
+ onConnectionChange: (connected) => {
66
+ log.info(`Webhooks service connection: ${connected ? "connected" : "disconnected"}`);
67
+ },
68
+ logger: log
69
+ });
70
+ webhooksClient.start();
71
+ log.info("Webhooks service client started");
72
+ } else log.info("Webhooks service URL not configured — running without webhooks relay");
73
+ });
100
74
  };
101
75
  const stopWebhooksService = () => {
102
- globalThis.__alfeWebhooksPluginActivated = false;
103
76
  if (webhooksClient) {
104
77
  webhooksClient.stop();
105
78
  webhooksClient = null;
@@ -114,6 +87,7 @@ const plugin = {
114
87
  }
115
88
  daemonIpcClient = null;
116
89
  }
90
+ resetActivation(WEBHOOKS_ACTIVATION_KEY);
117
91
  log.info("Alfe Webhooks plugin deactivated");
118
92
  };
119
93
  if (typeof api.registerGatewayMethod === "function") {
@@ -190,7 +164,6 @@ const plugin = {
190
164
  log.info("Alfe Webhooks plugin activated");
191
165
  },
192
166
  deactivate(api) {
193
- globalThis.__alfeWebhooksPluginActivated = false;
194
167
  const log = api.logger;
195
168
  log.info("Alfe Webhooks plugin deactivating...");
196
169
  if (webhooksClient) {
@@ -207,6 +180,7 @@ const plugin = {
207
180
  }
208
181
  daemonIpcClient = null;
209
182
  }
183
+ resetActivation(WEBHOOKS_ACTIVATION_KEY);
210
184
  log.info("Alfe Webhooks plugin deactivated");
211
185
  }
212
186
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alfe.ai/openclaw-webhooks",
3
- "version": "0.0.18",
3
+ "version": "0.0.19",
4
4
  "description": "OpenClaw webhooks plugin for Alfe — receive and manage external webhooks",
5
5
  "type": "module",
6
6
  "main": "./dist/plugin.js",
@@ -28,7 +28,8 @@
28
28
  ],
29
29
  "dependencies": {
30
30
  "ws": "^8.18.0",
31
- "@alfe.ai/config": "0.3.0",
31
+ "@alfe.ai/config": "0.4.0",
32
+ "@alfe.ai/openclaw-plugin-kit": "0.1.0",
32
33
  "@alfe.ai/webhooks": "^0.0.3"
33
34
  },
34
35
  "peerDependencies": {