@alfe.ai/openclaw 0.0.1

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/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # @alfe.ai/openclaw
2
+
3
+ OpenClaw plugin that connects to the local Alfe gateway daemon via IPC.
4
+
5
+ ## What It Does
6
+
7
+ - Connects to the Alfe gateway daemon at `~/.alfe/gateway.sock`
8
+ - Registers OpenClaw capabilities (sessions, tools, plugins) with the daemon
9
+ - Re-registers automatically on reconnect (daemon may restart)
10
+ - Gracefully handles daemon being unavailable
11
+
12
+ ## Usage
13
+
14
+ ```js
15
+ // openclaw.config.js
16
+ export default {
17
+ plugins: {
18
+ entries: {
19
+ '@alfe.ai/openclaw': {},
20
+ },
21
+ },
22
+ };
23
+ ```
24
+
25
+ The daemon socket path defaults to `~/.alfe/gateway.sock`. Override via config
26
+ (`socketPath`) or the `ALFE_GATEWAY_SOCKET` environment variable.
27
+
28
+ ## Setup
29
+
30
+ ```bash
31
+ alfe setup # Authenticate and install the gateway daemon
32
+ ```
33
+
34
+ ## Architecture
35
+
36
+ ```
37
+ Alfe Cloud ←—— WebSocket ——→ alfe-gateway daemon (always-on)
38
+ ↕ IPC (~/.alfe/gateway.sock)
39
+ @alfe.ai/openclaw (this plugin)
40
+
41
+ OpenClaw process
42
+ ```
43
+
44
+ The plugin is a thin IPC client. All heavy lifting (cloud connection, auth,
45
+ protocol translation) is handled by the daemon.
46
+
47
+ ## Note
48
+
49
+ Integration management (install, remove, configure, health) is handled by
50
+ the gateway service directly — this plugin does not process integration
51
+ commands.
@@ -0,0 +1,186 @@
1
+ import plugin from "./plugin.js";
2
+ import { EventEmitter } from "node:events";
3
+
4
+ //#region src/types.d.ts
5
+
6
+ /**
7
+ * IPC protocol types for communication with the Alfe gateway daemon.
8
+ *
9
+ * These match the protocol defined in @alfe.ai/gateway (packages/gateway/src/protocol.ts).
10
+ * Duplicated here to avoid a direct dependency on the daemon package
11
+ * (the daemon is a standalone process, not a library dependency).
12
+ */
13
+ interface IPCRequest {
14
+ type: 'req';
15
+ id: string;
16
+ method: string;
17
+ params: Record<string, unknown>;
18
+ }
19
+ interface IPCResponse {
20
+ id: string;
21
+ ok: boolean;
22
+ payload?: unknown;
23
+ error?: {
24
+ code: string;
25
+ message: string;
26
+ };
27
+ }
28
+ interface IPCEvent {
29
+ type: 'event';
30
+ event: string;
31
+ payload: unknown;
32
+ }
33
+ interface RegisterResult {
34
+ status: string;
35
+ daemonVersion: string;
36
+ protocolVersion: number;
37
+ }
38
+ declare function isIPCRequest(msg: unknown): msg is IPCRequest;
39
+ declare function isIPCResponse(msg: unknown): msg is IPCResponse;
40
+ declare function isIPCEvent(msg: unknown): msg is IPCEvent;
41
+ /** IPC protocol version — must match daemon's PROTOCOL_VERSION */
42
+ declare const PROTOCOL_VERSION = 1;
43
+ //#endregion
44
+ //#region src/ipc-client.d.ts
45
+
46
+ declare class IPCClient extends EventEmitter {
47
+ private socket;
48
+ private socketPath;
49
+ private buffer;
50
+ private backoffMs;
51
+ private closed;
52
+ private _connected;
53
+ private reconnectTimer;
54
+ private pending;
55
+ private log;
56
+ constructor(socketPath: string);
57
+ get connected(): boolean;
58
+ /**
59
+ * Start the IPC connection with auto-reconnect.
60
+ */
61
+ start(): void;
62
+ /**
63
+ * Stop the IPC connection and all timers.
64
+ */
65
+ stop(): void;
66
+ /**
67
+ * Send a request to the daemon and wait for a response.
68
+ */
69
+ request(method: string, params?: Record<string, unknown>, timeoutMs?: number): Promise<IPCResponse>;
70
+ /**
71
+ * Send a response to a daemon request.
72
+ * Used internally by the request event handler.
73
+ */
74
+ sendResponse(response: IPCResponse): void;
75
+ private doConnect;
76
+ private processBuffer;
77
+ private handleResponse;
78
+ private handleIncomingRequest;
79
+ private scheduleReconnect;
80
+ private clearReconnectTimer;
81
+ }
82
+ //#endregion
83
+ //#region src/capability-reporter.d.ts
84
+ /**
85
+ * Register this OpenClaw plugin with the daemon.
86
+ * Should be called on every (re)connect.
87
+ *
88
+ * @returns Registration result or null on failure
89
+ */
90
+ declare function registerWithDaemon(client: IPCClient, log: {
91
+ info(msg: string, ...args: unknown[]): void;
92
+ warn(msg: string, ...args: unknown[]): void;
93
+ error(msg: string, ...args: unknown[]): void;
94
+ }): Promise<RegisterResult | null>;
95
+ //#endregion
96
+ //#region ../../packages-internal/agent-client/dist/types.d.ts
97
+ interface BaseClientOptions {
98
+ url: string;
99
+ token: string;
100
+ clientId: string;
101
+ displayName: string;
102
+ version?: string;
103
+ instanceId?: string;
104
+ maxPayload?: number;
105
+ logger?: Logger;
106
+ }
107
+ interface Logger {
108
+ info(msg: string, ...args: unknown[]): void;
109
+ warn(msg: string, ...args: unknown[]): void;
110
+ error(msg: string, ...args: unknown[]): void;
111
+ debug(msg: string, ...args: unknown[]): void;
112
+ }
113
+ //# sourceMappingURL=types.d.ts.map
114
+ //#endregion
115
+ //#region ../../packages-internal/agent-client/dist/base-client.d.ts
116
+ declare abstract class BaseAgentClient {
117
+ private ws;
118
+ private connected;
119
+ private closed;
120
+ private backoffMs;
121
+ private pending;
122
+ private readyResolve;
123
+ private readyReject;
124
+ private readyPromise;
125
+ protected readonly log: Logger;
126
+ protected readonly opts: BaseClientOptions;
127
+ protected readonly instanceId: string;
128
+ constructor(opts: BaseClientOptions);
129
+ get isConnected(): boolean;
130
+ start(): Promise<void>;
131
+ stop(): void;
132
+ request(method: string, params: Record<string, unknown>, opts?: {
133
+ expectFinal?: boolean;
134
+ timeoutMs?: number;
135
+ }): Promise<unknown>;
136
+ /** Perform protocol-specific handshake after WebSocket opens. */
137
+ protected abstract performHandshake(): Promise<void>;
138
+ /**
139
+ * Handle a protocol event. Base implementation handles 'chat' events.
140
+ * Subclasses should override and call super for unhandled events.
141
+ */
142
+ protected handleEvent(event: string, payload: unknown): void;
143
+ /** Called after successful handshake. Override to add service registration, health beacons, etc. */
144
+ protected onConnected(): void | Promise<void>;
145
+ /** Called when the connection is lost or stopped. Override to clean up timers, etc. */
146
+ protected onDisconnected(): void;
147
+ /** Close the underlying WebSocket connection. Useful for subclass timeout handling. */
148
+ protected closeConnection(code: number, reason: string): void;
149
+ /** Mark the client as connected and resolve the ready promise. */
150
+ protected setConnected(): void;
151
+ /** Resolve the ready promise (call after handshake + onConnected). */
152
+ protected resolveReady(): void;
153
+ /** Reject the ready promise (call on handshake failure). */
154
+ protected rejectReady(err: Error): void;
155
+ protected doConnect(): void;
156
+ private initiateHandshake;
157
+ private handleMessage;
158
+ private scheduleReconnect;
159
+ private flushPending;
160
+ }
161
+ //# sourceMappingURL=base-client.d.ts.map
162
+ //#endregion
163
+ //#region src/ws-client.d.ts
164
+ interface OpenClawClientOptions extends BaseClientOptions {
165
+ /** Role for the connect handshake. Defaults to 'operator'. */
166
+ role?: string;
167
+ /** Scopes for the connect handshake. Defaults to ['operator.admin']. */
168
+ scopes?: string[];
169
+ }
170
+ declare class OpenClawGatewayAdapter extends BaseAgentClient {
171
+ private tickTimer;
172
+ private lastTick;
173
+ private handshakeInFlight;
174
+ private readonly openclawOpts;
175
+ constructor(opts: OpenClawClientOptions);
176
+ protected performHandshake(): Promise<void>;
177
+ protected handleEvent(event: string, payload: unknown): void;
178
+ protected onDisconnected(): void;
179
+ private startTickWatch;
180
+ /** Parse the standard agent response format into plain text. */
181
+ static parseAgentResponse(response: unknown): string;
182
+ /** Format a session key with the standard agent prefix. */
183
+ static formatSessionKey(agentId: string, sessionKey: string): string;
184
+ }
185
+ //#endregion
186
+ export { IPCClient, IPCEvent, IPCRequest, IPCResponse, type OpenClawClientOptions, OpenClawGatewayAdapter, PROTOCOL_VERSION, RegisterResult, isIPCEvent, isIPCRequest, isIPCResponse, plugin, registerWithDaemon };