@alfe.ai/openclaw-webhooks 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/dist/index.cjs ADDED
@@ -0,0 +1,3 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_plugin = require("./plugin.cjs");
3
+ exports.plugin = require_plugin;
@@ -0,0 +1,2 @@
1
+ import { i as WebhooksPluginConfig, n as Logger, r as OpenClawPluginApi, t as plugin } from "./plugin.cjs";
2
+ export { type Logger, type OpenClawPluginApi, type WebhooksPluginConfig, plugin };
@@ -0,0 +1,183 @@
1
+ let _alfe_ai_webhooks = require("@alfe.ai/webhooks");
2
+ let _alfe_ai_config = require("@alfe.ai/config");
3
+ //#region src/plugin.ts
4
+ /**
5
+ * @alfe.ai/openclaw-webhooks — OpenClaw webhooks plugin.
6
+ *
7
+ * Receives webhook deliveries from the Alfe webhooks service and
8
+ * exposes tools for the agent to manage its own webhooks.
9
+ *
10
+ * Follows the same pattern as @alfe.ai/openclaw-chat:
11
+ * - Connects to Alfe daemon IPC for capability registration
12
+ * - Connects to webhooks service WS for real-time delivery
13
+ * - Registers gateway RPC methods for webhook management
14
+ * - Exposes agent-callable tools for self-service CRUD
15
+ */
16
+ const WEBHOOKS_CAPABILITIES = ["webhooks.receive", "webhooks.manage"];
17
+ let daemonIpcClient = null;
18
+ let webhooksClient = null;
19
+ /**
20
+ * Attempt to connect to the Alfe daemon IPC socket.
21
+ */
22
+ async function connectToDaemon(socketPath, log) {
23
+ try {
24
+ const IPCClientCtor = (await import("@alfe.ai/openclaw")).IPCClient;
25
+ const client = new IPCClientCtor(socketPath, log);
26
+ client.on("connected", async () => {
27
+ log.info("Connected to Alfe daemon — registering webhooks capabilities...");
28
+ const response = await client.request("capability.register", {
29
+ plugin: "@alfe.ai/openclaw-webhooks",
30
+ capabilities: [...WEBHOOKS_CAPABILITIES]
31
+ });
32
+ if (response.ok) log.info("Webhooks capabilities registered with daemon");
33
+ else log.warn(`Failed to register webhooks capabilities: ${response.error?.message ?? "unknown"}`);
34
+ });
35
+ client.on("disconnected", (reason) => {
36
+ log.warn(`Disconnected from Alfe daemon: ${String(reason)}`);
37
+ });
38
+ client.on("error", (err) => {
39
+ log.debug(`Daemon IPC error: ${err.message}`);
40
+ });
41
+ client.start();
42
+ return client;
43
+ } catch {
44
+ log.info("Alfe daemon not available — webhooks plugin running standalone");
45
+ return null;
46
+ }
47
+ }
48
+ const plugin = {
49
+ id: "@alfe.ai/openclaw-webhooks",
50
+ name: "Alfe Webhooks Plugin",
51
+ description: "Receive and manage HTTP webhooks from external services",
52
+ version: "0.1.0",
53
+ activate(api) {
54
+ const log = api.logger;
55
+ const alreadyActivated = globalThis.__alfeWebhooksPluginActivated === true;
56
+ globalThis.__alfeWebhooksPluginActivated = true;
57
+ if (alreadyActivated) log.debug("Alfe Webhooks plugin re-registering gateway methods");
58
+ else log.info("Alfe Webhooks plugin activating...");
59
+ if (!alreadyActivated) {
60
+ const pluginConfig = (api.config ?? {}).plugins?.entries?.["@alfe.ai/openclaw-webhooks"]?.config ?? {};
61
+ let alfeConfig = null;
62
+ try {
63
+ alfeConfig = (0, _alfe_ai_config.resolveConfig)();
64
+ } catch {
65
+ log.info("Could not resolve Alfe config — daemon IPC and webhooks WS auth unavailable");
66
+ }
67
+ connectToDaemon(pluginConfig.daemonSocket ?? alfeConfig?.socketPath ?? _alfe_ai_config.DEFAULT_SOCKET_PATH, log).then((client) => {
68
+ daemonIpcClient = client;
69
+ }).catch((err) => {
70
+ log.debug(`Daemon connect failed: ${err.message}`);
71
+ });
72
+ const webhooksWsUrl = pluginConfig.webhooksWsUrl;
73
+ const apiKey = alfeConfig?.apiKey;
74
+ if (webhooksWsUrl && apiKey) {
75
+ log.info(`Connecting to webhooks service: ${webhooksWsUrl}`);
76
+ webhooksClient = new _alfe_ai_webhooks.WebhooksServiceClient({
77
+ wsUrl: webhooksWsUrl,
78
+ apiKey,
79
+ onWebhook: (delivery) => {
80
+ log.info(`Webhook received: ${delivery.name} (${delivery.webhookId}) provider=${delivery.provider}`);
81
+ if (daemonIpcClient) daemonIpcClient.request("event.emit", {
82
+ event: "webhook.received",
83
+ payload: delivery
84
+ }).catch((err) => {
85
+ log.debug(`Failed to emit webhook event to daemon: ${err.message}`);
86
+ });
87
+ },
88
+ onConnectionChange: (connected) => {
89
+ log.info(`Webhooks service connection: ${connected ? "connected" : "disconnected"}`);
90
+ },
91
+ logger: log
92
+ });
93
+ webhooksClient.start();
94
+ log.info("Webhooks service client started");
95
+ } else log.info("Webhooks service URL not configured — running without webhooks relay");
96
+ }
97
+ if (typeof api.registerGatewayMethod === "function") {
98
+ api.registerGatewayMethod("webhooks.create", async (...args) => {
99
+ const params = args[0];
100
+ if (!daemonIpcClient) return {
101
+ ok: false,
102
+ error: "Daemon not connected"
103
+ };
104
+ const response = await daemonIpcClient.request("webhooks.create", params);
105
+ return response.ok ? response.payload : {
106
+ ok: false,
107
+ error: response.error?.message
108
+ };
109
+ });
110
+ api.registerGatewayMethod("webhooks.list", async () => {
111
+ if (!daemonIpcClient) return {
112
+ ok: false,
113
+ error: "Daemon not connected"
114
+ };
115
+ const response = await daemonIpcClient.request("webhooks.list", {});
116
+ return response.ok ? response.payload : {
117
+ ok: false,
118
+ error: response.error?.message
119
+ };
120
+ });
121
+ api.registerGatewayMethod("webhooks.delete", async (...args) => {
122
+ const params = args[0];
123
+ if (!daemonIpcClient) return {
124
+ ok: false,
125
+ error: "Daemon not connected"
126
+ };
127
+ const response = await daemonIpcClient.request("webhooks.delete", params);
128
+ return response.ok ? response.payload : {
129
+ ok: false,
130
+ error: response.error?.message
131
+ };
132
+ });
133
+ api.registerGatewayMethod("webhooks.rotate", async (...args) => {
134
+ const params = args[0];
135
+ if (!daemonIpcClient) return {
136
+ ok: false,
137
+ error: "Daemon not connected"
138
+ };
139
+ const response = await daemonIpcClient.request("webhooks.rotate", params);
140
+ return response.ok ? response.payload : {
141
+ ok: false,
142
+ error: response.error?.message
143
+ };
144
+ });
145
+ api.registerGatewayMethod("webhooks.deliveries", async (...args) => {
146
+ const params = args[0];
147
+ if (!daemonIpcClient) return {
148
+ ok: false,
149
+ error: "Daemon not connected"
150
+ };
151
+ const response = await daemonIpcClient.request("webhooks.deliveries", params);
152
+ return response.ok ? response.payload : {
153
+ ok: false,
154
+ error: response.error?.message
155
+ };
156
+ });
157
+ log.info("Registered gateway RPC methods: webhooks.create, webhooks.list, webhooks.delete, webhooks.rotate, webhooks.deliveries");
158
+ }
159
+ log.info("Alfe Webhooks plugin activated");
160
+ },
161
+ deactivate(api) {
162
+ globalThis.__alfeWebhooksPluginActivated = false;
163
+ const log = api.logger;
164
+ log.info("Alfe Webhooks plugin deactivating...");
165
+ if (webhooksClient) {
166
+ webhooksClient.stop();
167
+ webhooksClient = null;
168
+ log.info("Webhooks service client stopped");
169
+ }
170
+ if (daemonIpcClient) {
171
+ try {
172
+ daemonIpcClient.stop();
173
+ log.info("Disconnected from Alfe daemon");
174
+ } catch (err) {
175
+ log.debug(`Error disconnecting from daemon: ${err.message}`);
176
+ }
177
+ daemonIpcClient = null;
178
+ }
179
+ log.info("Alfe Webhooks plugin deactivated");
180
+ }
181
+ };
182
+ //#endregion
183
+ module.exports = plugin;
@@ -0,0 +1,48 @@
1
+ //#region src/types.d.ts
2
+ /**
3
+ * Types for the Alfe webhooks plugin.
4
+ */
5
+ interface WebhooksPluginConfig {
6
+ /** Alfe daemon IPC socket path override. */
7
+ daemonSocket?: string;
8
+ /** Webhooks service WebSocket URL (e.g. wss://webhooks.dev.alfe.ai/ws) */
9
+ webhooksWsUrl?: string;
10
+ /** API key for webhooks service auth */
11
+ apiKey?: string;
12
+ }
13
+ interface Logger {
14
+ info(msg: string, ...args: unknown[]): void;
15
+ warn(msg: string, ...args: unknown[]): void;
16
+ error(msg: string, ...args: unknown[]): void;
17
+ debug(msg: string, ...args: unknown[]): void;
18
+ }
19
+ interface OpenClawConfig {
20
+ plugins?: {
21
+ entries?: Record<string, {
22
+ config?: WebhooksPluginConfig;
23
+ [key: string]: unknown;
24
+ }>;
25
+ [key: string]: unknown;
26
+ };
27
+ [key: string]: unknown;
28
+ }
29
+ interface OpenClawPluginApi {
30
+ logger: Logger;
31
+ config?: OpenClawConfig;
32
+ registerGatewayMethod?(name: string, handler: (...args: unknown[]) => Promise<unknown>): void;
33
+ on(event: string, handler: (...args: unknown[]) => void | Promise<void>, options?: {
34
+ priority?: number;
35
+ }): void;
36
+ }
37
+ //#endregion
38
+ //#region src/plugin.d.ts
39
+ declare const plugin: {
40
+ id: string;
41
+ name: string;
42
+ description: string;
43
+ version: string;
44
+ activate(api: OpenClawPluginApi): void;
45
+ deactivate(api: OpenClawPluginApi): void;
46
+ };
47
+ //#endregion
48
+ export { WebhooksPluginConfig as i, Logger as n, OpenClawPluginApi as r, plugin as t };
@@ -0,0 +1,2 @@
1
+ import { t as plugin } from "./plugin.cjs";
2
+ export { plugin as default };
package/package.json CHANGED
@@ -1,18 +1,20 @@
1
1
  {
2
2
  "name": "@alfe.ai/openclaw-webhooks",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "description": "OpenClaw webhooks plugin for Alfe — receive and manage external webhooks",
5
5
  "type": "module",
6
6
  "main": "./dist/plugin.js",
7
7
  "types": "./dist/index.d.ts",
8
8
  "exports": {
9
9
  ".": {
10
- "import": "./dist/index.js",
11
- "types": "./dist/index.d.ts"
10
+ "types": "./dist/index.d.ts",
11
+ "require": "./dist/index.cjs",
12
+ "import": "./dist/index.js"
12
13
  },
13
14
  "./plugin": {
14
- "import": "./dist/plugin.js",
15
- "types": "./dist/plugin.d.ts"
15
+ "types": "./dist/plugin.d.ts",
16
+ "require": "./dist/plugin.cjs",
17
+ "import": "./dist/plugin.js"
16
18
  }
17
19
  },
18
20
  "openclaw": {
@@ -26,8 +28,8 @@
26
28
  ],
27
29
  "dependencies": {
28
30
  "ws": "^8.18.0",
29
- "@alfe.ai/config": "0.0.6",
30
- "@alfe.ai/webhooks": "^0.0.1"
31
+ "@alfe.ai/config": "0.0.7",
32
+ "@alfe.ai/webhooks": "^0.0.2"
31
33
  },
32
34
  "license": "UNLICENSED",
33
35
  "scripts": {