@alfe.ai/gateway 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.
@@ -0,0 +1,164 @@
1
+ //#region src/protocol.d.ts
2
+
3
+ interface IPCRequest {
4
+ type: 'req';
5
+ id: string;
6
+ method: string;
7
+ params: Record<string, unknown>;
8
+ }
9
+ interface IPCResponse {
10
+ id: string;
11
+ ok: boolean;
12
+ payload?: unknown;
13
+ error?: {
14
+ code: string;
15
+ message: string;
16
+ };
17
+ }
18
+ interface IPCEvent {
19
+ type: 'event';
20
+ event: string;
21
+ payload: unknown;
22
+ }
23
+ /** Current IPC protocol version */
24
+ declare const PROTOCOL_VERSION = 1;
25
+ //#endregion
26
+ //#region src/daemon.d.ts
27
+
28
+ declare function startDaemon(): Promise<void>;
29
+ //#endregion
30
+ //#region src/config.d.ts
31
+ /**
32
+ * Daemon configuration — reads ~/.alfe/config.toml and resolves agent identity.
33
+ *
34
+ * Bootstrap flow:
35
+ * 1. Read api_key from ~/.alfe/config.toml (via @alfe.ai/config)
36
+ * 2. Derive API endpoint from token prefix
37
+ * 3. Call /auth/validate to get tenantId (orgId)
38
+ * 4. Use tokenId as agent identity for cloud registration
39
+ */
40
+ interface AgentWorkspaceConfig {
41
+ personalityKey?: string;
42
+ files: Record<string, string>;
43
+ }
44
+ declare const ALFE_DIR: string;
45
+ declare const SOCKET_PATH: string;
46
+ declare const PID_PATH: string;
47
+ interface RuntimeConfig {
48
+ workspace: string;
49
+ }
50
+ interface DaemonConfig {
51
+ apiKey: string;
52
+ apiEndpoint: string;
53
+ gatewayWsUrl: string;
54
+ socketPath: string;
55
+ pidPath: string;
56
+ agentId: string;
57
+ orgId: string;
58
+ runtime: string;
59
+ /** Runtime configurations keyed by runtime name (e.g. 'openclaw') */
60
+ runtimes: Record<string, RuntimeConfig>;
61
+ }
62
+ interface AgentIdentity {
63
+ agentId: string;
64
+ orgId: string;
65
+ runtime: string;
66
+ }
67
+ /**
68
+ * Resolve agent identity by validating the api_key with the auth service.
69
+ * Returns agentId (derived from tokenId) and orgId (tenantId).
70
+ */
71
+ declare function resolveAgentIdentity(apiKey: string, apiEndpoint: string): Promise<AgentIdentity>;
72
+ /**
73
+ * Whether the daemon is running in managed mode (ECS Fargate container).
74
+ * In managed mode, configuration comes from environment variables instead
75
+ * of ~/.alfe/config.toml, and IPC/PID features are disabled.
76
+ */
77
+
78
+ /**
79
+ * Load full daemon configuration.
80
+ * Reads config.toml, validates the API key, resolves agent identity,
81
+ * and parses runtime configurations.
82
+ *
83
+ * In managed mode, loads from environment variables instead.
84
+ */
85
+ declare function loadDaemonConfig(): Promise<DaemonConfig>;
86
+ /**
87
+ * Fetch agent workspace config from the API.
88
+ *
89
+ * 1. GET /agents/me/workspace → { personalityKey }
90
+ * 2. If personalityKey set, GET /personalities/:key/files → persona file contents
91
+ *
92
+ * Returns null if the agent has no personality assigned or the fetch fails.
93
+ */
94
+ declare function fetchAgentConfig(apiKey: string, apiEndpoint: string): Promise<AgentWorkspaceConfig | null>;
95
+ //#endregion
96
+ //#region src/health.d.ts
97
+ /**
98
+ * Health reporting — used by `alfe doctor` and `alfe gateway status`.
99
+ *
100
+ * Connects to the daemon's IPC socket and queries health information.
101
+ * Works even when the daemon is the only thing running (OpenClaw can be down).
102
+ */
103
+ interface DaemonHealth {
104
+ daemon: {
105
+ status: 'running' | 'stopped' | 'unreachable';
106
+ pid?: number;
107
+ uptime?: number;
108
+ version?: string;
109
+ };
110
+ cloud: {
111
+ status: 'connected' | 'disconnected' | 'unknown';
112
+ latencyMs?: number;
113
+ };
114
+ plugins: {
115
+ name: string;
116
+ version: string;
117
+ capabilities: string[];
118
+ connectedAt: number;
119
+ lastSeen: number;
120
+ }[];
121
+ commandQueue: {
122
+ totalPending: number;
123
+ };
124
+ }
125
+ /**
126
+ * Query daemon health via IPC socket.
127
+ * Used by `alfe doctor` and `alfe gateway status`.
128
+ */
129
+ declare function queryDaemonHealth(socketPath: string, timeoutMs?: number): Promise<DaemonHealth>;
130
+ /**
131
+ * Format health info for terminal display.
132
+ */
133
+ declare function formatHealthReport(health: DaemonHealth): string;
134
+ //#endregion
135
+ //#region src/process-manager.d.ts
136
+ /**
137
+ * Process management — launchd/systemd service installation.
138
+ *
139
+ * Generates and installs user-space service units for auto-start on boot.
140
+ * No root required — uses user agents (Mac) or user units (Linux).
141
+ */
142
+ /**
143
+ * Install the service unit for the current platform.
144
+ */
145
+ declare function installService(): Promise<string>;
146
+ /**
147
+ * Uninstall the service unit for the current platform.
148
+ */
149
+ declare function uninstallService(): Promise<string>;
150
+ /**
151
+ * Write the current process PID to the PID file.
152
+ */
153
+
154
+ /**
155
+ * Check if a daemon is already running.
156
+ * Returns the PID if alive, null if not running.
157
+ */
158
+ declare function checkExistingDaemon(): Promise<number | null>;
159
+ /**
160
+ * Send SIGTERM to an existing daemon process.
161
+ */
162
+ declare function stopExistingDaemon(): Promise<boolean>;
163
+ //#endregion
164
+ export { ALFE_DIR, type AgentIdentity, type AgentWorkspaceConfig, type DaemonConfig, type DaemonHealth, type IPCEvent, type IPCRequest, type IPCResponse, PID_PATH, PROTOCOL_VERSION, SOCKET_PATH, checkExistingDaemon, fetchAgentConfig, formatHealthReport, installService, loadDaemonConfig, queryDaemonHealth, resolveAgentIdentity, startDaemon, stopExistingDaemon, uninstallService };
@@ -0,0 +1,2 @@
1
+ import { a as installService, c as PROTOCOL_VERSION, d as SOCKET_PATH, f as fetchAgentConfig, i as checkExistingDaemon, l as ALFE_DIR, m as resolveAgentIdentity, n as queryDaemonHealth, o as stopExistingDaemon, p as loadDaemonConfig, r as startDaemon, s as uninstallService, t as formatHealthReport, u as PID_PATH } from "../health.js";
2
+ export { ALFE_DIR, PID_PATH, PROTOCOL_VERSION, SOCKET_PATH, checkExistingDaemon, fetchAgentConfig, formatHealthReport, installService, loadDaemonConfig, queryDaemonHealth, resolveAgentIdentity, startDaemon, stopExistingDaemon, uninstallService };
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@alfe.ai/gateway",
3
+ "version": "0.0.1",
4
+ "description": "Alfe local gateway daemon — persistent control plane for agent integrations",
5
+ "type": "module",
6
+ "bin": {
7
+ "alfe-gateway": "./dist/bin/gateway.js"
8
+ },
9
+ "main": "./dist/src/index.js",
10
+ "types": "./dist/src/index.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "import": "./dist/src/index.js",
14
+ "types": "./dist/src/index.d.ts"
15
+ }
16
+ },
17
+ "files": [
18
+ "dist"
19
+ ],
20
+ "dependencies": {
21
+ "pino": "^9.6.0",
22
+ "smol-toml": "^1.3.0",
23
+ "pino-roll": "^1.2.0",
24
+ "ws": "^8.18.0",
25
+ "@alfe.ai/config": "^0.0.1",
26
+ "@alfe.ai/integrations": "^0.0.1"
27
+ },
28
+ "devDependencies": {
29
+ "@types/ws": "^8.5.13",
30
+ "tsx": "^4.19.0",
31
+ "@alfe/ids": "0.1.0"
32
+ },
33
+ "license": "UNLICENSED",
34
+ "scripts": {
35
+ "build": "tsdown",
36
+ "dev": "tsdown --watch",
37
+ "start": "node dist/bin/gateway.js",
38
+ "typecheck": "tsc --noEmit",
39
+ "test": "vitest run",
40
+ "test:watch": "vitest",
41
+ "test:coverage": "vitest run --coverage",
42
+ "lint": "eslint ."
43
+ }
44
+ }